{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang-nursery/rand/issues/59","labels_url":"https://api.github.com/repos/rust-lang-nursery/rand/issues/59/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang-nursery/rand/issues/59/comments","events_url":"https://api.github.com/repos/rust-lang-nursery/rand/issues/59/events","html_url":"https://github.com/rust-lang-nursery/rand/pull/59","id":95661005,"number":59,"title":"Faster and Better weak generators","user":{"login":"arthurprs","id":715958,"avatar_url":"https://avatars.githubusercontent.com/u/715958?v=3","gravatar_id":"","url":"https://api.github.com/users/arthurprs","html_url":"https://github.com/arthurprs","followers_url":"https://api.github.com/users/arthurprs/followers","following_url":"https://api.github.com/users/arthurprs/following{/other_user}","gists_url":"https://api.github.com/users/arthurprs/gists{/gist_id}","starred_url":"https://api.github.com/users/arthurprs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arthurprs/subscriptions","organizations_url":"https://api.github.com/users/arthurprs/orgs","repos_url":"https://api.github.com/users/arthurprs/repos","events_url":"https://api.github.com/users/arthurprs/events{/privacy}","received_events_url":"https://api.github.com/users/arthurprs/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":37,"created_at":"2015-07-17T13:57:34Z","updated_at":"2015-12-18T10:25:53Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rust-lang-nursery/rand/pulls/59","html_url":"https://github.com/rust-lang-nursery/rand/pull/59","diff_url":"https://github.com/rust-lang-nursery/rand/pull/59.diff","patch_url":"https://github.com/rust-lang-nursery/rand/pull/59.patch"},"body":"I took a couple of days to research some fast pseudo-random number generators and I thought it'd be nice to contribute to the crate.\r\n\r\nThis PR contains two commits one adding the xorshift128+ and the other PCG RXS M XS (32 and 64bit variants). I don't think there's precedence for adding both, so I think we should discuss how to proceed.\r\n\r\n| Algorithm    | Size     | Quality | x86 (u32) | x86 (u64) | x64 (u32) | x64 (u64) |\r\n|--------------|----------|---------|-----------|-----------|-----------|-----------|\r\n| PCG32        | 4 Bytes  | Fair    | 1365      | 1616      | 1646      | 1677      |\r\n| PCG64        | 8 Bytes  | Great   | 510       | 1016      | 1646      | 3493      |\r\n| Xorshift128   | 16 Bytes | Fair     | 1486      | 1895      | 2094      | 2279      |\r\n| Xorshift128+ | 16 Bytes | Great   | 911       | 1656      | 2000      | 4278      |\r\n\r\nx64 benchmarks (my laptop)\r\n```\r\ntest algorithms::chacha_u32                        ... bench:       2,477 ns/iter (+/- 191) = 161 MB/s\r\ntest algorithms::chacha_u64                        ... bench:       4,783 ns/iter (+/- 353) = 167 MB/s\r\ntest algorithms::isaac64_u32                       ... bench:         617 ns/iter (+/- 40) = 648 MB/s\r\ntest algorithms::isaac64_u64                       ... bench:         639 ns/iter (+/- 16) = 1251 MB/s\r\ntest algorithms::isaac_u32                         ... bench:         847 ns/iter (+/- 30) = 472 MB/s\r\ntest algorithms::isaac_u64                         ... bench:       1,579 ns/iter (+/- 130) = 506 MB/s\r\ntest algorithms::pcg32_u32                         ... bench:         243 ns/iter (+/- 10) = 1646 MB/s\r\ntest algorithms::pcg32_u64                         ... bench:         477 ns/iter (+/- 23) = 1677 MB/s\r\ntest algorithms::pcg64_u32                         ... bench:         243 ns/iter (+/- 14) = 1646 MB/s\r\ntest algorithms::pcg64_u64                         ... bench:         229 ns/iter (+/- 16) = 3493 MB/s\r\ntest algorithms::xorshift_u32                      ... bench:         191 ns/iter (+/- 11) = 2094 MB/s\r\ntest algorithms::xorshift_u64                      ... bench:         351 ns/iter (+/- 18) = 2279 MB/s\r\ntest algorithms::xorshiftp_u32                     ... bench:         200 ns/iter (+/- 11) = 2000 MB/s\r\ntest algorithms::xorshiftp_u64                     ... bench:         187 ns/iter (+/- 7) = 4278 MB/s\r\n\r\n```\r\nx86 benchmarks (DO)\r\n```\r\ntest algorithms::chacha_u32                        ... bench:       2,644 ns/iter (+/- 21) = 151 MB/s\r\ntest algorithms::chacha_u64                        ... bench:       4,964 ns/iter (+/- 28) = 161 MB/s\r\ntest algorithms::isaac64_u32                       ... bench:       1,038 ns/iter (+/- 8) = 385 MB/s\r\ntest algorithms::isaac64_u64                       ... bench:       1,059 ns/iter (+/- 6) = 755 MB/s\r\ntest algorithms::isaac_u32                         ... bench:       1,107 ns/iter (+/- 12) = 361 MB/s\r\ntest algorithms::isaac_u64                         ... bench:       2,004 ns/iter (+/- 13) = 399 MB/s\r\ntest algorithms::pcg32_u32                         ... bench:         293 ns/iter (+/- 4) = 1365 MB/s\r\ntest algorithms::pcg32_u64                         ... bench:         495 ns/iter (+/- 6) = 1616 MB/s\r\ntest algorithms::pcg64_u32                         ... bench:         783 ns/iter (+/- 15) = 510 MB/s\r\ntest algorithms::pcg64_u64                         ... bench:         787 ns/iter (+/- 9) = 1016 MB/s\r\ntest algorithms::xorshift_u32                      ... bench:         269 ns/iter (+/- 4) = 1486 MB/s\r\ntest algorithms::xorshift_u64                      ... bench:         422 ns/iter (+/- 6) = 1895 MB/s\r\ntest algorithms::xorshiftp_u32                     ... bench:         439 ns/iter (+/- 7) = 911 MB/s\r\ntest algorithms::xorshiftp_u64                     ... bench:         483 ns/iter (+/- 5) = 1656 MB/s\r\n```\r\n\r\nPCG is neat, it's very compact and provide good quality, even in the 32bit variant!\r\n\r\nAlthough my preference would be to add the xorshift128+ variant and leave the xorshift128 there (probably worth a rename though).\r\n\r\nIn addition weak_rng should return the fastest algorithm available for the architectures. As 64bit operations kills performance in 32bit architectures this can be as simple as Xorshift64 for 32bit and Xorshift128+ for 64bit.\r\n\r\nFinally, users won't need to look elsewhere for a crazy fast random implementation.\r\n\r\nThoughts?"},"comment":{"url":"https://api.github.com/repos/rust-lang-nursery/rand/issues/comments/165741207","html_url":"https://github.com/rust-lang-nursery/rand/pull/59#issuecomment-165741207","issue_url":"https://api.github.com/repos/rust-lang-nursery/rand/issues/59","id":165741207,"user":{"login":"arthurprs","id":715958,"avatar_url":"https://avatars.githubusercontent.com/u/715958?v=3","gravatar_id":"","url":"https://api.github.com/users/arthurprs","html_url":"https://github.com/arthurprs","followers_url":"https://api.github.com/users/arthurprs/followers","following_url":"https://api.github.com/users/arthurprs/following{/other_user}","gists_url":"https://api.github.com/users/arthurprs/gists{/gist_id}","starred_url":"https://api.github.com/users/arthurprs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arthurprs/subscriptions","organizations_url":"https://api.github.com/users/arthurprs/orgs","repos_url":"https://api.github.com/users/arthurprs/repos","events_url":"https://api.github.com/users/arthurprs/events{/privacy}","received_events_url":"https://api.github.com/users/arthurprs/received_events","type":"User","site_admin":false},"created_at":"2015-12-18T10:25:53Z","updated_at":"2015-12-18T10:25:53Z","body":"What I meant is that xorshift128+ is a great choice for the weak generator.\r\n\r\nI don't really get why so much resistance against this. 99,9% of time you just want a good distribution. And the default generator already is the secure one."}}