diff --git a/.github/workflows/benches.yml b/.github/workflows/benches.yml index 22b4baa..3cd3ca3 100644 --- a/.github/workflows/benches.yml +++ b/.github/workflows/benches.yml @@ -6,13 +6,11 @@ on: paths-ignore: - "**.md" - "distr_test/**" - - "examples/**" pull_request: branches: [ master ] paths-ignore: - "**.md" - "distr_test/**" - - "examples/**" defaults: run: diff --git a/.github/workflows/distr_test.yml b/.github/workflows/distr_test.yml index f2b7f81..3cafb8d 100644 --- a/.github/workflows/distr_test.yml +++ b/.github/workflows/distr_test.yml @@ -6,13 +6,11 @@ on: paths-ignore: - "**.md" - "benches/**" - - "examples/**" pull_request: branches: [ master ] paths-ignore: - "**.md" - "benches/**" - - "examples/**" defaults: run: diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml deleted file mode 100644 index 1d83a77..0000000 --- a/.github/workflows/gh-pages.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: gh-pages - -permissions: - contents: read - pages: write - id-token: write - -on: - push: - branches: - - master - -jobs: - deploy: - name: GH-pages documentation - runs-on: ubuntu-latest - environment: - name: github-pages - url: https://rust-random.github.io/rand/ - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Install toolchain - uses: dtolnay/rust-toolchain@nightly - - - name: Build docs - env: - RUSTDOCFLAGS: --cfg doc_cfg - # --all builds all crates, but with default features for other crates (okay in this case) - run: | - cargo doc --all --all-features --no-deps - cp utils/redirect.html target/doc/index.html - rm target/doc/.lock - - - name: Setup Pages - uses: actions/configure-pages@v5 - - - name: Upload artifact - uses: actions/upload-pages-artifact@v3 - with: - path: './target/doc' - - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 293d5f4..696cb12 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,16 +43,8 @@ jobs: uses: dtolnay/rust-toolchain@master with: toolchain: nightly - - name: rand - run: cargo doc --all-features --no-deps - - name: rand_core - run: cargo doc --all-features --package rand_core --no-deps - name: rand_distr run: cargo doc --all-features --package rand_distr --no-deps - - name: rand_chacha - run: cargo doc --all-features --package rand_chacha --no-deps - - name: rand_pcg - run: cargo doc --all-features --package rand_pcg --no-deps test: runs-on: ${{ matrix.os }} @@ -102,35 +94,11 @@ jobs: if: ${{ matrix.variant == 'minimal_versions' }} run: | cargo generate-lockfile -Z minimal-versions - - name: Maybe nightly - if: ${{ matrix.toolchain == 'nightly' }} - run: | - cargo test --target ${{ matrix.target }} --features=nightly - cargo test --target ${{ matrix.target }} --all-features - cargo test --target ${{ matrix.target }} --lib --tests --no-default-features - - name: Test rand - run: | - cargo test --target ${{ matrix.target }} --lib --tests --no-default-features - cargo build --target ${{ matrix.target }} --no-default-features --features alloc,os_rng,small_rng,unbiased - cargo test --target ${{ matrix.target }} --lib --tests --no-default-features --features=alloc,os_rng,small_rng - cargo test --target ${{ matrix.target }} --examples - - name: Test rand (all stable features) - run: | - cargo test --target ${{ matrix.target }} --features=serde,log,small_rng - - name: Test rand_core - run: | - cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml - cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml --no-default-features - cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml --no-default-features --features=os_rng - name: Test rand_distr run: | - cargo test --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --features=serde - cargo test --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --no-default-features - cargo test --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --no-default-features --features=std,std_math - - name: Test rand_pcg - run: cargo test --target ${{ matrix.target }} --manifest-path rand_pcg/Cargo.toml --features=serde - - name: Test rand_chacha - run: cargo test --target ${{ matrix.target }} --manifest-path rand_chacha/Cargo.toml --features=serde + cargo test --target ${{ matrix.target }} --features=serde + cargo test --target ${{ matrix.target }} --no-default-features + cargo test --target ${{ matrix.target }} --no-default-features --features=std,std_math test-cross: runs-on: ${{ matrix.os }} @@ -159,63 +127,4 @@ jobs: - name: Test run: | # all stable features: - cross test --no-fail-fast --target ${{ matrix.target }} --features=serde,log,small_rng - cross test --no-fail-fast --target ${{ matrix.target }} --examples - cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml - cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --features=serde - cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_pcg/Cargo.toml --features=serde - cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_chacha/Cargo.toml - - test-miri: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install toolchain - run: | - rustup toolchain install nightly --component miri - rustup override set nightly - cargo miri setup - - name: Test rand - run: | - cargo miri test --no-default-features --lib --tests - cargo miri test --features=log,small_rng - cargo miri test --manifest-path rand_core/Cargo.toml - cargo miri test --manifest-path rand_core/Cargo.toml --features=serde - cargo miri test --manifest-path rand_core/Cargo.toml --no-default-features - #cargo miri test --manifest-path rand_distr/Cargo.toml # no unsafe and lots of slow tests - cargo miri test --manifest-path rand_pcg/Cargo.toml --features=serde - cargo miri test --manifest-path rand_chacha/Cargo.toml --no-default-features - - test-no-std: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install toolchain - uses: dtolnay/rust-toolchain@nightly - with: - target: thumbv6m-none-eabi - - name: Build top-level only - run: cargo build --target=thumbv6m-none-eabi --no-default-features - - # Disabled due to lack of known working compiler versions (not older than our MSRV) - # test-avr: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v4 - # - name: Install toolchain - # uses: dtolnay/rust-toolchain@nightly - # with: - # components: rust-src - # - name: Build top-level only - # run: cargo build -Z build-std=core --target=avr-unknown-gnu-atmega328 --no-default-features - - test-ios: - runs-on: macos-latest - steps: - - uses: actions/checkout@v4 - - name: Install toolchain - uses: dtolnay/rust-toolchain@nightly - with: - target: aarch64-apple-ios - - name: Build top-level only - run: cargo build --target=aarch64-apple-ios + cross test --no-fail-fast --target ${{ matrix.target }} --features=serde diff --git a/rand_distr/CHANGELOG.md b/CHANGELOG.md similarity index 100% rename from rand_distr/CHANGELOG.md rename to CHANGELOG.md diff --git a/rand_distr/COPYRIGHT b/COPYRIGHT similarity index 100% rename from rand_distr/COPYRIGHT rename to COPYRIGHT diff --git a/Cargo.lock.msrv b/Cargo.lock.msrv new file mode 100644 index 0000000..b37c0d4 --- /dev/null +++ b/Cargo.lock.msrv @@ -0,0 +1,714 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "average" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a237a6822e1c3c98e700b6db5b293eb341b7524dcb8d227941245702b7431dc" +dependencies = [ + "easy-cast", + "float-ord", + "num-traits", +] + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "bitflags" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" + +[[package]] +name = "bumpalo" +version = "3.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "755717a7de9ec452bf7f3f1a3099085deabd7f2962b861dae91ecd7a365903d2" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-targets", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", + "serde", +] + +[[package]] +name = "easy-cast" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72852736692ec862655eca398c9bb1b476161b563c9f80f45f4808b9629750d6" +dependencies = [ + "libm", +] + +[[package]] +name = "float-ord" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce81f49ae8a0482e4c55ea62ebbd7e5a686af544c00b9d090bba3ff9be97b3d" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "getrandom" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8" +dependencies = [ + "cfg-if", + "libc", + "wasi", + "windows-targets", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" + +[[package]] +name = "js-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "lambert_w" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b0c98033daa8d13aa2171722fd201bae337924189091f7988bdaff5301fa8c9" +dependencies = [ + "libm", +] + +[[package]] +name = "libc" +version = "0.2.169" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" + +[[package]] +name = "libm" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" + +[[package]] +name = "log" +version = "0.4.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy 0.7.35", +] + +[[package]] +name = "proc-macro2" +version = "1.0.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" +dependencies = [ + "rand_chacha", + "rand_core", + "serde", + "zerocopy 0.8.16", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b08f3c9802962f7e1b25113931d94f43ed9725bebc59db9d0c3e9a23b67e15ff" +dependencies = [ + "getrandom", + "serde", + "zerocopy 0.8.16", +] + +[[package]] +name = "rand_distr" +version = "0.5.0" +dependencies = [ + "average", + "num-traits", + "rand", + "rand_pcg", + "serde", + "serde_with", + "special", +] + +[[package]] +name = "rand_pcg" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b48ac3f7ffaab7fac4d2376632268aa5f89abdb55f7ebf8f4d11fffccb2320f7" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rustversion" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" + +[[package]] +name = "ryu" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd" + +[[package]] +name = "serde" +version = "1.0.217" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.217" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.138" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_with" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21e47d95bc83ed33b2ecf84f4187ad1ab9685d18ff28db000c99deac8ce180e3" +dependencies = [ + "base64", + "chrono", + "hex", + "indexmap", + "serde", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea3cee93715c2e266b9338b7544da68a9f24e227722ba482bd1c024367c77c65" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "special" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15e561befc4a32ae79f0c3c391ed2f1d30d86a4c5bc08668f080e8daa417a2f9" +dependencies = [ + "lambert_w", + "libm", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "time" +version = "0.3.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "unicode-ident" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034" + +[[package]] +name = "wasi" +version = "0.13.3+wasi-0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26816d2e1a4a36a2940b96c5296ce403917633dff8f3440e9b236ed6f6bacad2" +dependencies = [ + "wit-bindgen-rt", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "wit-bindgen-rt" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3268f3d866458b787f390cf61f4bbb563b922d091359f9608842999eaee3943c" +dependencies = [ + "bitflags", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive 0.7.35", +] + +[[package]] +name = "zerocopy" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b8c07a70861ce02bad1607b5753ecb2501f67847b9f9ada7c160fff0ec6300c" +dependencies = [ + "zerocopy-derive 0.8.16", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5226bc9a9a9836e7428936cde76bb6b22feea1a8bfdbc0d241136e4d13417e25" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/rand_distr/Cargo.toml b/Cargo.toml similarity index 85% rename from rand_distr/Cargo.toml rename to Cargo.toml index dd55673..0e3d709 100644 --- a/rand_distr/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.5.0" authors = ["The Rand Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" -repository = "https://github.com/rust-random/rand" +repository = "https://github.com/rust-random/rand_distr" documentation = "https://docs.rs/rand_distr" homepage = "https://rust-random.github.io/book" description = """ @@ -33,15 +33,15 @@ std_math = ["num-traits/std"] serde = ["dep:serde", "dep:serde_with", "rand/serde"] [dependencies] -rand = { path = "..", version = "0.9.0", default-features = false } +rand = { version = "0.9.0", default-features = false } num-traits = { version = "0.2", default-features = false, features = ["libm"] } serde = { version = "1.0.103", features = ["derive"], optional = true } serde_with = { version = ">= 3.0, <= 3.11", optional = true } [dev-dependencies] -rand_pcg = { version = "0.9.0", path = "../rand_pcg" } +rand_pcg = { version = "0.9.0" } # For inline examples -rand = { path = "..", version = "0.9.0", features = ["small_rng"] } +rand = { version = "0.9.0", features = ["small_rng"] } # Histogram implementation for testing uniformity average = { version = "0.15", features = [ "std" ] } # Special functions for testing distributions diff --git a/rand_distr/LICENSE-APACHE b/LICENSE-APACHE similarity index 100% rename from rand_distr/LICENSE-APACHE rename to LICENSE-APACHE diff --git a/rand_distr/LICENSE-MIT b/LICENSE-MIT similarity index 100% rename from rand_distr/LICENSE-MIT rename to LICENSE-MIT diff --git a/rand_distr/README.md b/README.md similarity index 100% rename from rand_distr/README.md rename to README.md diff --git a/benches/Cargo.toml b/benches/Cargo.toml index a143bff..e2978a6 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -7,49 +7,16 @@ publish = false [dependencies] [dev-dependencies] -rand = { path = "..", features = ["small_rng", "nightly"] } -rand_pcg = { path = "../rand_pcg" } -rand_chacha = { path = "../rand_chacha" } -rand_distr = { path = "../rand_distr" } +rand = { version = "0.9.0", features = ["small_rng", "nightly"] } +rand_pcg = "0.9.0" +rand_distr = { path = ".." } criterion = "0.5" criterion-cycles-per-byte = "0.6" -[[bench]] -name = "array" -harness = false - -[[bench]] -name = "bool" -harness = false - [[bench]] name = "distr" harness = false -[[bench]] -name = "generators" -harness = false - -[[bench]] -name = "seq_choose" -harness = false - -[[bench]] -name = "shuffle" -harness = false - -[[bench]] -name = "standard" -harness = false - -[[bench]] -name = "uniform" -harness = false - -[[bench]] -name = "uniform_float" -harness = false - [[bench]] name = "weighted" harness = false diff --git a/benches/benches/array.rs b/benches/benches/array.rs deleted file mode 100644 index 0635163..0000000 --- a/benches/benches/array.rs +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2018-2023 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Generating/filling arrays and iterators of output - -use criterion::{criterion_group, criterion_main, Criterion}; -use rand::distr::StandardUniform; -use rand::prelude::*; -use rand_pcg::Pcg64Mcg; - -criterion_group!( - name = benches; - config = Criterion::default(); - targets = bench -); -criterion_main!(benches); - -pub fn bench(c: &mut Criterion) { - let mut g = c.benchmark_group("random_1kb"); - g.throughput(criterion::Throughput::Bytes(1024)); - - g.bench_function("u16_iter_repeat", |b| { - use core::iter; - let mut rng = Pcg64Mcg::from_rng(&mut rand::rng()); - b.iter(|| { - let v: Vec = iter::repeat(()).map(|()| rng.random()).take(512).collect(); - v - }); - }); - - g.bench_function("u16_sample_iter", |b| { - let mut rng = Pcg64Mcg::from_rng(&mut rand::rng()); - b.iter(|| { - let v: Vec = StandardUniform.sample_iter(&mut rng).take(512).collect(); - v - }); - }); - - g.bench_function("u16_gen_array", |b| { - let mut rng = Pcg64Mcg::from_rng(&mut rand::rng()); - b.iter(|| { - let v: [u16; 512] = rng.random(); - v - }); - }); - - g.bench_function("u16_fill", |b| { - let mut rng = Pcg64Mcg::from_rng(&mut rand::rng()); - let mut buf = [0u16; 512]; - b.iter(|| { - rng.fill(&mut buf[..]); - buf - }); - }); - - g.bench_function("u64_iter_repeat", |b| { - use core::iter; - let mut rng = Pcg64Mcg::from_rng(&mut rand::rng()); - b.iter(|| { - let v: Vec = iter::repeat(()).map(|()| rng.random()).take(128).collect(); - v - }); - }); - - g.bench_function("u64_sample_iter", |b| { - let mut rng = Pcg64Mcg::from_rng(&mut rand::rng()); - b.iter(|| { - let v: Vec = StandardUniform.sample_iter(&mut rng).take(128).collect(); - v - }); - }); - - g.bench_function("u64_gen_array", |b| { - let mut rng = Pcg64Mcg::from_rng(&mut rand::rng()); - b.iter(|| { - let v: [u64; 128] = rng.random(); - v - }); - }); - - g.bench_function("u64_fill", |b| { - let mut rng = Pcg64Mcg::from_rng(&mut rand::rng()); - let mut buf = [0u64; 128]; - b.iter(|| { - rng.fill(&mut buf[..]); - buf - }); - }); -} diff --git a/benches/benches/bool.rs b/benches/benches/bool.rs deleted file mode 100644 index 8ff8c67..0000000 --- a/benches/benches/bool.rs +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Generating/filling arrays and iterators of output - -use criterion::{criterion_group, criterion_main, Criterion}; -use rand::distr::Bernoulli; -use rand::prelude::*; -use rand_pcg::Pcg32; - -criterion_group!( - name = benches; - config = Criterion::default(); - targets = bench -); -criterion_main!(benches); - -pub fn bench(c: &mut Criterion) { - let mut g = c.benchmark_group("random_bool"); - g.sample_size(1000); - g.warm_up_time(core::time::Duration::from_millis(500)); - g.measurement_time(core::time::Duration::from_millis(1000)); - - g.bench_function("standard", |b| { - let mut rng = Pcg32::from_rng(&mut rand::rng()); - b.iter(|| rng.sample::(rand::distr::StandardUniform)) - }); - - g.bench_function("const", |b| { - let mut rng = Pcg32::from_rng(&mut rand::rng()); - b.iter(|| rng.random_bool(0.18)) - }); - - g.bench_function("var", |b| { - let mut rng = Pcg32::from_rng(&mut rand::rng()); - let p = rng.random(); - b.iter(|| rng.random_bool(p)) - }); - - g.bench_function("ratio_const", |b| { - let mut rng = Pcg32::from_rng(&mut rand::rng()); - b.iter(|| rng.random_ratio(2, 3)) - }); - - g.bench_function("ratio_var", |b| { - let mut rng = Pcg32::from_rng(&mut rand::rng()); - let d = rng.random_range(1..=100); - let n = rng.random_range(0..=d); - b.iter(|| rng.random_ratio(n, d)); - }); - - g.bench_function("bernoulli_const", |b| { - let mut rng = Pcg32::from_rng(&mut rand::rng()); - let d = Bernoulli::new(0.18).unwrap(); - b.iter(|| rng.sample(d)) - }); - - g.bench_function("bernoulli_var", |b| { - let mut rng = Pcg32::from_rng(&mut rand::rng()); - let p = rng.random(); - let d = Bernoulli::new(p).unwrap(); - b.iter(|| rng.sample(d)) - }); -} diff --git a/benches/benches/generators.rs b/benches/benches/generators.rs deleted file mode 100644 index 64325ce..0000000 --- a/benches/benches/generators.rs +++ /dev/null @@ -1,221 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use core::time::Duration; -use criterion::measurement::WallTime; -use criterion::{black_box, criterion_group, criterion_main, BenchmarkGroup, Criterion}; -use rand::prelude::*; -use rand::rngs::ReseedingRng; -use rand::rngs::{mock::StepRng, OsRng}; -use rand_chacha::rand_core::UnwrapErr; -use rand_chacha::{ChaCha12Rng, ChaCha20Core, ChaCha20Rng, ChaCha8Rng}; -use rand_pcg::{Pcg32, Pcg64, Pcg64Dxsm, Pcg64Mcg}; - -criterion_group!( - name = benches; - config = Criterion::default(); - targets = random_bytes, random_u32, random_u64, init_gen, init_from_u64, init_from_seed, reseeding_bytes -); -criterion_main!(benches); - -pub fn random_bytes(c: &mut Criterion) { - let mut g = c.benchmark_group("random_bytes"); - g.warm_up_time(Duration::from_millis(500)); - g.measurement_time(Duration::from_millis(1000)); - g.throughput(criterion::Throughput::Bytes(1024)); - - fn bench(g: &mut BenchmarkGroup, name: &str, mut rng: impl Rng) { - g.bench_function(name, |b| { - let mut buf = [0u8; 1024]; - b.iter(|| { - rng.fill_bytes(&mut buf); - black_box(buf); - }); - }); - } - - bench(&mut g, "step", StepRng::new(0, 1)); - bench(&mut g, "pcg32", Pcg32::from_rng(&mut rand::rng())); - bench(&mut g, "pcg64", Pcg64::from_rng(&mut rand::rng())); - bench(&mut g, "pcg64mcg", Pcg64Mcg::from_rng(&mut rand::rng())); - bench(&mut g, "pcg64dxsm", Pcg64Dxsm::from_rng(&mut rand::rng())); - bench(&mut g, "chacha8", ChaCha8Rng::from_rng(&mut rand::rng())); - bench(&mut g, "chacha12", ChaCha12Rng::from_rng(&mut rand::rng())); - bench(&mut g, "chacha20", ChaCha20Rng::from_rng(&mut rand::rng())); - bench(&mut g, "std", StdRng::from_rng(&mut rand::rng())); - bench(&mut g, "small", SmallRng::from_rng(&mut rand::rng())); - bench(&mut g, "os", UnwrapErr(OsRng)); - bench(&mut g, "thread", rand::rng()); - - g.finish() -} - -pub fn random_u32(c: &mut Criterion) { - let mut g = c.benchmark_group("random_u32"); - g.sample_size(1000); - g.warm_up_time(Duration::from_millis(500)); - g.measurement_time(Duration::from_millis(1000)); - g.throughput(criterion::Throughput::Bytes(4)); - - fn bench(g: &mut BenchmarkGroup, name: &str, mut rng: impl Rng) { - g.bench_function(name, |b| { - b.iter(|| rng.random::()); - }); - } - - bench(&mut g, "step", StepRng::new(0, 1)); - bench(&mut g, "pcg32", Pcg32::from_rng(&mut rand::rng())); - bench(&mut g, "pcg64", Pcg64::from_rng(&mut rand::rng())); - bench(&mut g, "pcg64mcg", Pcg64Mcg::from_rng(&mut rand::rng())); - bench(&mut g, "pcg64dxsm", Pcg64Dxsm::from_rng(&mut rand::rng())); - bench(&mut g, "chacha8", ChaCha8Rng::from_rng(&mut rand::rng())); - bench(&mut g, "chacha12", ChaCha12Rng::from_rng(&mut rand::rng())); - bench(&mut g, "chacha20", ChaCha20Rng::from_rng(&mut rand::rng())); - bench(&mut g, "std", StdRng::from_rng(&mut rand::rng())); - bench(&mut g, "small", SmallRng::from_rng(&mut rand::rng())); - bench(&mut g, "os", UnwrapErr(OsRng)); - bench(&mut g, "thread", rand::rng()); - - g.finish() -} - -pub fn random_u64(c: &mut Criterion) { - let mut g = c.benchmark_group("random_u64"); - g.sample_size(1000); - g.warm_up_time(Duration::from_millis(500)); - g.measurement_time(Duration::from_millis(1000)); - g.throughput(criterion::Throughput::Bytes(8)); - - fn bench(g: &mut BenchmarkGroup, name: &str, mut rng: impl Rng) { - g.bench_function(name, |b| { - b.iter(|| rng.random::()); - }); - } - - bench(&mut g, "step", StepRng::new(0, 1)); - bench(&mut g, "pcg32", Pcg32::from_rng(&mut rand::rng())); - bench(&mut g, "pcg64", Pcg64::from_rng(&mut rand::rng())); - bench(&mut g, "pcg64mcg", Pcg64Mcg::from_rng(&mut rand::rng())); - bench(&mut g, "pcg64dxsm", Pcg64Dxsm::from_rng(&mut rand::rng())); - bench(&mut g, "chacha8", ChaCha8Rng::from_rng(&mut rand::rng())); - bench(&mut g, "chacha12", ChaCha12Rng::from_rng(&mut rand::rng())); - bench(&mut g, "chacha20", ChaCha20Rng::from_rng(&mut rand::rng())); - bench(&mut g, "std", StdRng::from_rng(&mut rand::rng())); - bench(&mut g, "small", SmallRng::from_rng(&mut rand::rng())); - bench(&mut g, "os", UnwrapErr(OsRng)); - bench(&mut g, "thread", rand::rng()); - - g.finish() -} - -pub fn init_gen(c: &mut Criterion) { - let mut g = c.benchmark_group("init_gen"); - g.warm_up_time(Duration::from_millis(500)); - g.measurement_time(Duration::from_millis(1000)); - - fn bench(g: &mut BenchmarkGroup, name: &str) { - g.bench_function(name, |b| { - let mut rng = Pcg32::from_rng(&mut rand::rng()); - b.iter(|| R::from_rng(&mut rng)); - }); - } - - bench::(&mut g, "pcg32"); - bench::(&mut g, "pcg64"); - bench::(&mut g, "pcg64mcg"); - bench::(&mut g, "pcg64dxsm"); - bench::(&mut g, "chacha8"); - bench::(&mut g, "chacha12"); - bench::(&mut g, "chacha20"); - bench::(&mut g, "std"); - bench::(&mut g, "small"); - - g.finish() -} - -pub fn init_from_u64(c: &mut Criterion) { - let mut g = c.benchmark_group("init_from_u64"); - g.warm_up_time(Duration::from_millis(500)); - g.measurement_time(Duration::from_millis(1000)); - - fn bench(g: &mut BenchmarkGroup, name: &str) { - g.bench_function(name, |b| { - let mut rng = Pcg32::from_rng(&mut rand::rng()); - let seed = rng.random(); - b.iter(|| R::seed_from_u64(black_box(seed))); - }); - } - - bench::(&mut g, "pcg32"); - bench::(&mut g, "pcg64"); - bench::(&mut g, "pcg64mcg"); - bench::(&mut g, "pcg64dxsm"); - bench::(&mut g, "chacha8"); - bench::(&mut g, "chacha12"); - bench::(&mut g, "chacha20"); - bench::(&mut g, "std"); - bench::(&mut g, "small"); - - g.finish() -} - -pub fn init_from_seed(c: &mut Criterion) { - let mut g = c.benchmark_group("init_from_seed"); - g.warm_up_time(Duration::from_millis(500)); - g.measurement_time(Duration::from_millis(1000)); - - fn bench(g: &mut BenchmarkGroup, name: &str) - where - rand::distr::StandardUniform: Distribution<::Seed>, - { - g.bench_function(name, |b| { - let mut rng = Pcg32::from_rng(&mut rand::rng()); - let seed = rng.random(); - b.iter(|| R::from_seed(black_box(seed.clone()))); - }); - } - - bench::(&mut g, "pcg32"); - bench::(&mut g, "pcg64"); - bench::(&mut g, "pcg64mcg"); - bench::(&mut g, "pcg64dxsm"); - bench::(&mut g, "chacha8"); - bench::(&mut g, "chacha12"); - bench::(&mut g, "chacha20"); - bench::(&mut g, "std"); - bench::(&mut g, "small"); - - g.finish() -} - -pub fn reseeding_bytes(c: &mut Criterion) { - let mut g = c.benchmark_group("reseeding_bytes"); - g.warm_up_time(Duration::from_millis(500)); - g.throughput(criterion::Throughput::Bytes(1024 * 1024)); - - fn bench(g: &mut BenchmarkGroup, thresh: u64) { - let name = format!("chacha20_{}k", thresh); - g.bench_function(name.as_str(), |b| { - let mut rng = ReseedingRng::::new(thresh * 1024, OsRng).unwrap(); - let mut buf = [0u8; 1024 * 1024]; - b.iter(|| { - rng.fill_bytes(&mut buf); - black_box(&buf); - }); - }); - } - - bench(&mut g, 4); - bench(&mut g, 16); - bench(&mut g, 32); - bench(&mut g, 64); - bench(&mut g, 256); - bench(&mut g, 1024); - - g.finish() -} diff --git a/benches/benches/seq_choose.rs b/benches/benches/seq_choose.rs deleted file mode 100644 index 56223dd..0000000 --- a/benches/benches/seq_choose.rs +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright 2018-2023 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use rand::prelude::*; -use rand::SeedableRng; -use rand_pcg::Pcg32; - -criterion_group!( - name = benches; - config = Criterion::default(); - targets = bench -); -criterion_main!(benches); - -pub fn bench(c: &mut Criterion) { - c.bench_function("seq_slice_choose_1_of_100", |b| { - let mut rng = Pcg32::from_rng(&mut rand::rng()); - let mut buf = [0i32; 100]; - rng.fill(&mut buf); - let x = black_box(&mut buf); - - b.iter(|| x.choose(&mut rng).unwrap()); - }); - - let lens = [(1, 1000), (950, 1000), (10, 100), (90, 100)]; - for (amount, len) in lens { - let name = format!("seq_slice_choose_multiple_{}_of_{}", amount, len); - c.bench_function(name.as_str(), |b| { - let mut rng = Pcg32::from_rng(&mut rand::rng()); - let mut buf = [0i32; 1000]; - rng.fill(&mut buf); - let x = black_box(&buf[..len]); - - let mut results_buf = [0i32; 950]; - let y = black_box(&mut results_buf[..amount]); - let amount = black_box(amount); - - b.iter(|| { - // Collect full result to prevent unwanted shortcuts getting - // first element (in case sample_indices returns an iterator). - for (slot, sample) in y.iter_mut().zip(x.choose_multiple(&mut rng, amount)) { - *slot = *sample; - } - y[amount - 1] - }) - }); - } - - let lens = [(1, 1000), (950, 1000), (10, 100), (90, 100)]; - for (amount, len) in lens { - let name = format!("seq_slice_choose_multiple_weighted_{}_of_{}", amount, len); - c.bench_function(name.as_str(), |b| { - let mut rng = Pcg32::from_rng(&mut rand::rng()); - let mut buf = [0i32; 1000]; - rng.fill(&mut buf); - let x = black_box(&buf[..len]); - - let mut results_buf = [0i32; 950]; - let y = black_box(&mut results_buf[..amount]); - let amount = black_box(amount); - - b.iter(|| { - // Collect full result to prevent unwanted shortcuts getting - // first element (in case sample_indices returns an iterator). - let samples_iter = x.choose_multiple_weighted(&mut rng, amount, |_| 1.0).unwrap(); - for (slot, sample) in y.iter_mut().zip(samples_iter) { - *slot = *sample; - } - y[amount - 1] - }) - }); - } - - c.bench_function("seq_iter_choose_multiple_10_of_100", |b| { - let mut rng = Pcg32::from_rng(&mut rand::rng()); - let mut buf = [0i32; 100]; - rng.fill(&mut buf); - let x = black_box(&buf); - b.iter(|| x.iter().cloned().choose_multiple(&mut rng, 10)) - }); - - c.bench_function("seq_iter_choose_multiple_fill_10_of_100", |b| { - let mut rng = Pcg32::from_rng(&mut rand::rng()); - let mut buf = [0i32; 100]; - rng.fill(&mut buf); - let x = black_box(&buf); - let mut buf = [0; 10]; - b.iter(|| x.iter().cloned().choose_multiple_fill(&mut rng, &mut buf)) - }); - - bench_rng::(c, "ChaCha20"); - bench_rng::(c, "Pcg32"); - bench_rng::(c, "Pcg64"); -} - -fn bench_rng(c: &mut Criterion, rng_name: &'static str) { - for length in [1, 2, 3, 10, 100, 1000].map(black_box) { - let name = format!("choose_size-hinted_from_{length}_{rng_name}"); - c.bench_function(name.as_str(), |b| { - let mut rng = Rng::seed_from_u64(123); - b.iter(|| choose_size_hinted(length, &mut rng)) - }); - - let name = format!("choose_stable_from_{length}_{rng_name}"); - c.bench_function(name.as_str(), |b| { - let mut rng = Rng::seed_from_u64(123); - b.iter(|| choose_stable(length, &mut rng)) - }); - - let name = format!("choose_unhinted_from_{length}_{rng_name}"); - c.bench_function(name.as_str(), |b| { - let mut rng = Rng::seed_from_u64(123); - b.iter(|| choose_unhinted(length, &mut rng)) - }); - - let name = format!("choose_windowed_from_{length}_{rng_name}"); - c.bench_function(name.as_str(), |b| { - let mut rng = Rng::seed_from_u64(123); - b.iter(|| choose_windowed(length, 7, &mut rng)) - }); - } -} - -fn choose_size_hinted(max: usize, rng: &mut R) -> Option { - let iterator = 0..max; - iterator.choose(rng) -} - -fn choose_stable(max: usize, rng: &mut R) -> Option { - let iterator = 0..max; - iterator.choose_stable(rng) -} - -fn choose_unhinted(max: usize, rng: &mut R) -> Option { - let iterator = UnhintedIterator { iter: (0..max) }; - iterator.choose(rng) -} - -fn choose_windowed(max: usize, window_size: usize, rng: &mut R) -> Option { - let iterator = WindowHintedIterator { - iter: (0..max), - window_size, - }; - iterator.choose(rng) -} - -#[derive(Clone)] -struct UnhintedIterator { - iter: I, -} -impl Iterator for UnhintedIterator { - type Item = I::Item; - - fn next(&mut self) -> Option { - self.iter.next() - } -} - -#[derive(Clone)] -struct WindowHintedIterator { - iter: I, - window_size: usize, -} -impl Iterator for WindowHintedIterator { - type Item = I::Item; - - fn next(&mut self) -> Option { - self.iter.next() - } - - fn size_hint(&self) -> (usize, Option) { - (core::cmp::min(self.iter.len(), self.window_size), None) - } -} diff --git a/benches/benches/shuffle.rs b/benches/benches/shuffle.rs deleted file mode 100644 index c2f37da..0000000 --- a/benches/benches/shuffle.rs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2018-2023 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use rand::prelude::*; -use rand::SeedableRng; -use rand_pcg::Pcg32; - -criterion_group!( - name = benches; - config = Criterion::default(); - targets = bench -); -criterion_main!(benches); - -pub fn bench(c: &mut Criterion) { - c.bench_function("seq_shuffle_100", |b| { - let mut rng = Pcg32::from_rng(&mut rand::rng()); - let mut buf = [0i32; 100]; - rng.fill(&mut buf); - let x = black_box(&mut buf); - b.iter(|| { - x.shuffle(&mut rng); - x[0] - }) - }); - - bench_rng::(c, "ChaCha12"); - bench_rng::(c, "Pcg32"); - bench_rng::(c, "Pcg64"); -} - -fn bench_rng(c: &mut Criterion, rng_name: &'static str) { - for length in [1, 2, 3, 10, 100, 1000, 10000].map(black_box) { - c.bench_function(format!("shuffle_{length}_{rng_name}").as_str(), |b| { - let mut rng = Rng::seed_from_u64(123); - let mut vec: Vec = (0..length).collect(); - b.iter(|| { - vec.shuffle(&mut rng); - vec[0] - }) - }); - - if length >= 10 { - let name = format!("partial_shuffle_{length}_{rng_name}"); - c.bench_function(name.as_str(), |b| { - let mut rng = Rng::seed_from_u64(123); - let mut vec: Vec = (0..length).collect(); - b.iter(|| { - vec.partial_shuffle(&mut rng, length / 2); - vec[0] - }) - }); - } - } -} diff --git a/benches/benches/standard.rs b/benches/benches/standard.rs deleted file mode 100644 index ac38f02..0000000 --- a/benches/benches/standard.rs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2019 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use core::time::Duration; -use criterion::measurement::WallTime; -use criterion::{criterion_group, criterion_main, BenchmarkGroup, Criterion}; -use rand::distr::{Alphanumeric, StandardUniform}; -use rand::prelude::*; -use rand_distr::{Open01, OpenClosed01}; -use rand_pcg::Pcg64Mcg; - -criterion_group!( - name = benches; - config = Criterion::default(); - targets = bench -); -criterion_main!(benches); - -fn bench_ty(g: &mut BenchmarkGroup, name: &str) -where - D: Distribution + Default, -{ - g.throughput(criterion::Throughput::Bytes(size_of::() as u64)); - g.bench_function(name, |b| { - let mut rng = Pcg64Mcg::from_rng(&mut rand::rng()); - - b.iter(|| rng.sample::(D::default())); - }); -} - -pub fn bench(c: &mut Criterion) { - let mut g = c.benchmark_group("StandardUniform"); - g.sample_size(1000); - g.warm_up_time(Duration::from_millis(500)); - g.measurement_time(Duration::from_millis(1000)); - - macro_rules! do_ty { - ($t:ty) => { - bench_ty::<$t, StandardUniform>(&mut g, stringify!($t)); - }; - ($t:ty, $($tt:ty),*) => { - do_ty!($t); - do_ty!($($tt),*); - }; - } - - do_ty!(i8, i16, i32, i64, i128); - do_ty!(f32, f64); - do_ty!(char); - - bench_ty::(&mut g, "Alphanumeric"); - - bench_ty::(&mut g, "Open01/f32"); - bench_ty::(&mut g, "Open01/f64"); - bench_ty::(&mut g, "OpenClosed01/f32"); - bench_ty::(&mut g, "OpenClosed01/f64"); - - g.finish(); -} diff --git a/benches/benches/uniform.rs b/benches/benches/uniform.rs deleted file mode 100644 index ab1b0ed..0000000 --- a/benches/benches/uniform.rs +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2021 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implement benchmarks for uniform distributions over integer types - -use core::time::Duration; -use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; -use rand::distr::uniform::{SampleRange, Uniform}; -use rand::prelude::*; -use rand_chacha::ChaCha8Rng; -use rand_pcg::{Pcg32, Pcg64}; - -const WARM_UP_TIME: Duration = Duration::from_millis(1000); -const MEASUREMENT_TIME: Duration = Duration::from_secs(3); -const SAMPLE_SIZE: usize = 100_000; -const N_RESAMPLES: usize = 10_000; - -macro_rules! sample { - ($R:ty, $T:ty, $U:ty, $g:expr) => { - $g.bench_function(BenchmarkId::new(stringify!($R), "single"), |b| { - let mut rng = <$R>::from_rng(&mut rand::rng()); - let x = rng.random::<$U>(); - let bits = (<$T>::BITS / 2); - let mask = (1 as $U).wrapping_neg() >> bits; - let range = (x >> bits) * (x & mask); - let low = <$T>::MIN; - let high = low.wrapping_add(range as $T); - - b.iter(|| (low..=high).sample_single(&mut rng)); - }); - - $g.bench_function(BenchmarkId::new(stringify!($R), "distr"), |b| { - let mut rng = <$R>::from_rng(&mut rand::rng()); - let x = rng.random::<$U>(); - let bits = (<$T>::BITS / 2); - let mask = (1 as $U).wrapping_neg() >> bits; - let range = (x >> bits) * (x & mask); - let low = <$T>::MIN; - let high = low.wrapping_add(range as $T); - let dist = Uniform::<$T>::new_inclusive(<$T>::MIN, high).unwrap(); - - b.iter(|| dist.sample(&mut rng)); - }); - }; - - ($c:expr, $T:ty, $U:ty) => {{ - let mut g = $c.benchmark_group(concat!("sample", stringify!($T))); - g.sample_size(SAMPLE_SIZE); - g.warm_up_time(WARM_UP_TIME); - g.measurement_time(MEASUREMENT_TIME); - g.nresamples(N_RESAMPLES); - sample!(SmallRng, $T, $U, g); - sample!(ChaCha8Rng, $T, $U, g); - sample!(Pcg32, $T, $U, g); - sample!(Pcg64, $T, $U, g); - g.finish(); - }}; -} - -fn sample(c: &mut Criterion) { - sample!(c, i8, u8); - sample!(c, i16, u16); - sample!(c, i32, u32); - sample!(c, i64, u64); - sample!(c, i128, u128); -} - -criterion_group! { - name = benches; - config = Criterion::default(); - targets = sample -} -criterion_main!(benches); diff --git a/benches/benches/uniform_float.rs b/benches/benches/uniform_float.rs deleted file mode 100644 index 03a434f..0000000 --- a/benches/benches/uniform_float.rs +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2023 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implement benchmarks for uniform distributions over FP types -//! -//! Sampling methods compared: -//! -//! - sample: current method: (x12 - 1.0) * (b - a) + a - -use core::time::Duration; -use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; -use rand::distr::uniform::{SampleUniform, Uniform, UniformSampler}; -use rand::prelude::*; -use rand_chacha::ChaCha8Rng; -use rand_pcg::{Pcg32, Pcg64}; - -const WARM_UP_TIME: Duration = Duration::from_millis(1000); -const MEASUREMENT_TIME: Duration = Duration::from_secs(3); -const SAMPLE_SIZE: usize = 100_000; -const N_RESAMPLES: usize = 10_000; - -macro_rules! single_random { - ($R:ty, $T:ty, $g:expr) => { - $g.bench_function(BenchmarkId::new(stringify!($T), stringify!($R)), |b| { - let mut rng = <$R>::from_rng(&mut rand::rng()); - let (mut low, mut high); - loop { - low = <$T>::from_bits(rng.random()); - high = <$T>::from_bits(rng.random()); - if (low < high) && (high - low).is_normal() { - break; - } - } - - b.iter(|| <$T as SampleUniform>::Sampler::sample_single_inclusive(low, high, &mut rng)); - }); - }; - - ($c:expr, $T:ty) => {{ - let mut g = $c.benchmark_group("uniform_single"); - g.sample_size(SAMPLE_SIZE); - g.warm_up_time(WARM_UP_TIME); - g.measurement_time(MEASUREMENT_TIME); - g.nresamples(N_RESAMPLES); - single_random!(SmallRng, $T, g); - single_random!(ChaCha8Rng, $T, g); - single_random!(Pcg32, $T, g); - single_random!(Pcg64, $T, g); - g.finish(); - }}; -} - -fn single_random(c: &mut Criterion) { - single_random!(c, f32); - single_random!(c, f64); -} - -macro_rules! distr_random { - ($R:ty, $T:ty, $g:expr) => { - $g.bench_function(BenchmarkId::new(stringify!($T), stringify!($R)), |b| { - let mut rng = <$R>::from_rng(&mut rand::rng()); - let dist = loop { - let low = <$T>::from_bits(rng.random()); - let high = <$T>::from_bits(rng.random()); - if let Ok(dist) = Uniform::<$T>::new_inclusive(low, high) { - break dist; - } - }; - - b.iter(|| dist.sample(&mut rng)); - }); - }; - - ($c:expr, $T:ty) => {{ - let mut g = $c.benchmark_group("uniform_distribution"); - g.sample_size(SAMPLE_SIZE); - g.warm_up_time(WARM_UP_TIME); - g.measurement_time(MEASUREMENT_TIME); - g.nresamples(N_RESAMPLES); - distr_random!(SmallRng, $T, g); - distr_random!(ChaCha8Rng, $T, g); - distr_random!(Pcg32, $T, g); - distr_random!(Pcg64, $T, g); - g.finish(); - }}; -} - -fn distr_random(c: &mut Criterion) { - distr_random!(c, f32); - distr_random!(c, f64); -} - -criterion_group! { - name = benches; - config = Criterion::default(); - targets = single_random, distr_random -} -criterion_main!(benches); diff --git a/distr_test/Cargo.toml b/distr_test/Cargo.toml index d9d7fe2..9181d86 100644 --- a/distr_test/Cargo.toml +++ b/distr_test/Cargo.toml @@ -5,8 +5,8 @@ edition = "2021" publish = false [dev-dependencies] -rand_distr = { path = "../rand_distr", version = "0.5.0", default-features = false, features = ["alloc"] } -rand = { path = "..", version = "0.9.0", features = ["small_rng"] } +rand_distr = { path = "..", version = "0.5.0", default-features = false, features = ["alloc"] } +rand = { version = "0.9.0", features = ["small_rng"] } num-traits = "0.2.19" # Special functions for testing distributions special = "0.11.0" diff --git a/rand_distr/src/beta.rs b/src/beta.rs similarity index 100% rename from rand_distr/src/beta.rs rename to src/beta.rs diff --git a/rand_distr/src/binomial.rs b/src/binomial.rs similarity index 100% rename from rand_distr/src/binomial.rs rename to src/binomial.rs diff --git a/rand_distr/src/cauchy.rs b/src/cauchy.rs similarity index 100% rename from rand_distr/src/cauchy.rs rename to src/cauchy.rs diff --git a/rand_distr/src/chi_squared.rs b/src/chi_squared.rs similarity index 100% rename from rand_distr/src/chi_squared.rs rename to src/chi_squared.rs diff --git a/rand_distr/src/dirichlet.rs b/src/dirichlet.rs similarity index 100% rename from rand_distr/src/dirichlet.rs rename to src/dirichlet.rs diff --git a/rand_distr/src/exponential.rs b/src/exponential.rs similarity index 100% rename from rand_distr/src/exponential.rs rename to src/exponential.rs diff --git a/rand_distr/src/fisher_f.rs b/src/fisher_f.rs similarity index 100% rename from rand_distr/src/fisher_f.rs rename to src/fisher_f.rs diff --git a/rand_distr/src/frechet.rs b/src/frechet.rs similarity index 100% rename from rand_distr/src/frechet.rs rename to src/frechet.rs diff --git a/rand_distr/src/gamma.rs b/src/gamma.rs similarity index 100% rename from rand_distr/src/gamma.rs rename to src/gamma.rs diff --git a/rand_distr/src/geometric.rs b/src/geometric.rs similarity index 100% rename from rand_distr/src/geometric.rs rename to src/geometric.rs diff --git a/rand_distr/src/gumbel.rs b/src/gumbel.rs similarity index 100% rename from rand_distr/src/gumbel.rs rename to src/gumbel.rs diff --git a/rand_distr/src/hypergeometric.rs b/src/hypergeometric.rs similarity index 100% rename from rand_distr/src/hypergeometric.rs rename to src/hypergeometric.rs diff --git a/rand_distr/src/inverse_gaussian.rs b/src/inverse_gaussian.rs similarity index 100% rename from rand_distr/src/inverse_gaussian.rs rename to src/inverse_gaussian.rs diff --git a/rand_distr/src/lib.rs b/src/lib.rs similarity index 100% rename from rand_distr/src/lib.rs rename to src/lib.rs diff --git a/rand_distr/src/normal.rs b/src/normal.rs similarity index 100% rename from rand_distr/src/normal.rs rename to src/normal.rs diff --git a/rand_distr/src/normal_inverse_gaussian.rs b/src/normal_inverse_gaussian.rs similarity index 100% rename from rand_distr/src/normal_inverse_gaussian.rs rename to src/normal_inverse_gaussian.rs diff --git a/rand_distr/src/pareto.rs b/src/pareto.rs similarity index 100% rename from rand_distr/src/pareto.rs rename to src/pareto.rs diff --git a/rand_distr/src/pert.rs b/src/pert.rs similarity index 100% rename from rand_distr/src/pert.rs rename to src/pert.rs diff --git a/rand_distr/src/poisson.rs b/src/poisson.rs similarity index 100% rename from rand_distr/src/poisson.rs rename to src/poisson.rs diff --git a/rand_distr/src/skew_normal.rs b/src/skew_normal.rs similarity index 100% rename from rand_distr/src/skew_normal.rs rename to src/skew_normal.rs diff --git a/rand_distr/src/student_t.rs b/src/student_t.rs similarity index 100% rename from rand_distr/src/student_t.rs rename to src/student_t.rs diff --git a/rand_distr/src/triangular.rs b/src/triangular.rs similarity index 100% rename from rand_distr/src/triangular.rs rename to src/triangular.rs diff --git a/rand_distr/src/unit_ball.rs b/src/unit_ball.rs similarity index 100% rename from rand_distr/src/unit_ball.rs rename to src/unit_ball.rs diff --git a/rand_distr/src/unit_circle.rs b/src/unit_circle.rs similarity index 100% rename from rand_distr/src/unit_circle.rs rename to src/unit_circle.rs diff --git a/rand_distr/src/unit_disc.rs b/src/unit_disc.rs similarity index 100% rename from rand_distr/src/unit_disc.rs rename to src/unit_disc.rs diff --git a/rand_distr/src/unit_sphere.rs b/src/unit_sphere.rs similarity index 100% rename from rand_distr/src/unit_sphere.rs rename to src/unit_sphere.rs diff --git a/rand_distr/src/utils.rs b/src/utils.rs similarity index 100% rename from rand_distr/src/utils.rs rename to src/utils.rs diff --git a/rand_distr/src/weibull.rs b/src/weibull.rs similarity index 100% rename from rand_distr/src/weibull.rs rename to src/weibull.rs diff --git a/rand_distr/src/weighted/mod.rs b/src/weighted/mod.rs similarity index 100% rename from rand_distr/src/weighted/mod.rs rename to src/weighted/mod.rs diff --git a/rand_distr/src/weighted/weighted_alias.rs b/src/weighted/weighted_alias.rs similarity index 100% rename from rand_distr/src/weighted/weighted_alias.rs rename to src/weighted/weighted_alias.rs diff --git a/rand_distr/src/weighted/weighted_tree.rs b/src/weighted/weighted_tree.rs similarity index 100% rename from rand_distr/src/weighted/weighted_tree.rs rename to src/weighted/weighted_tree.rs diff --git a/rand_distr/src/zeta.rs b/src/zeta.rs similarity index 100% rename from rand_distr/src/zeta.rs rename to src/zeta.rs diff --git a/rand_distr/src/ziggurat_tables.rs b/src/ziggurat_tables.rs similarity index 100% rename from rand_distr/src/ziggurat_tables.rs rename to src/ziggurat_tables.rs diff --git a/rand_distr/src/zipf.rs b/src/zipf.rs similarity index 100% rename from rand_distr/src/zipf.rs rename to src/zipf.rs diff --git a/rand_distr/tests/value_stability.rs b/tests/value_stability.rs similarity index 100% rename from rand_distr/tests/value_stability.rs rename to tests/value_stability.rs