sapling/eden/mononoke/derived_data
Yan Soares Couto 30d4c8fc2d Make RNG in 'arbitrary' calls more correct
Summary:
Using modulo on arbitrary integers to get random numbers [isn't correct](https://www.internalfb.com/diff/D31305392 (da13975a4f)?dst_version_fbid=311037904117090&transaction_fbid=550270779610744), as the distribution between numbers isn't fair (unless the size is a power of two).

This was raised on D31305392 (da13975a4f), but we decided to land that quickly to unblock builds before doing these changes.

I'm applying the changes suggested on D31305392 (da13975a4f). This is what this diff does:
- For all cases where we generate small numbers (up to 5), replace with call to `Gen::choose`, so `u32::arbitrary(g) % 3` becomes `g.choose(&[0, 1, 2]).unwrap()`.
- For generating numbers in range 0..=1, I instead replaced with generating a boolean, which gets rid of the `unreachable!` calls.
- I removed the code to generate numbers in range 0..=0.
- For generating larger numbers, I used `u64::arbitrary` instead, which should make things "less wrong".

Some things I assumed, but am happy to change before landing, just let me know:
- Theoretically we don't *need* to change the code for `% 2` and `% 4`, as the math checks out there. I changed it for consistency there, but am happy to change it back.
- Using boolean also wasn't suggested initially, I'm happy to change back.

Reviewed By: krallin

Differential Revision: D31379381

fbshipit-source-id: a0bac26ebabd32a6c65f717512de998ef5dc37c8
2021-10-06 09:39:23 -07:00
..
blame Vendor curl-sys crate with patched curl 2021-10-04 03:13:50 -07:00
changeset_info Vendor curl-sys crate with patched curl 2021-10-04 03:13:50 -07:00
deleted_files_manifest Vendor curl-sys crate with patched curl 2021-10-04 03:13:50 -07:00
derived_generation Make RNG in 'arbitrary' calls more correct 2021-10-06 09:39:23 -07:00
fastlog Vendor curl-sys crate with patched curl 2021-10-04 03:13:50 -07:00
filenodes Daily common/rust/cargo_from_buck/bin/autocargo 2021-10-06 02:06:23 -07:00
fsnodes Vendor curl-sys crate with patched curl 2021-10-04 03:13:50 -07:00
manager derived_data_manager: mark batch-backfilled commits as derived 2021-10-06 06:31:20 -07:00
mercurial_derived_data Vendor curl-sys crate with patched curl 2021-10-04 03:13:50 -07:00
skeleton_manifest Vendor curl-sys crate with patched curl 2021-10-04 03:13:50 -07:00
src Cleanup old derived data 2021-10-06 06:01:42 -07:00
test Make RNG in 'arbitrary' calls more correct 2021-10-06 09:39:23 -07:00
test_utils Vendor curl-sys crate with patched curl 2021-10-04 03:13:50 -07:00
unodes Vendor curl-sys crate with patched curl 2021-10-04 03:13:50 -07:00
utils Cleanup old derived data 2021-10-06 06:01:42 -07:00
Cargo.toml Cleanup old derived data 2021-10-06 06:01:42 -07:00