stdrandom 0.3.0

Generate random numbers using only Rust standard library
Documentation
    use super::*;


fn fast_u64_for_test() -> u64 {
    use std::sync::atomic::{AtomicU64, Ordering};

    // Use an AtomicU64 to safely manage the counter across threads.
    // Atomic types provide methods for thread-safe operations.
    static COUNTER: AtomicU64 = AtomicU64::new(0);

    // `fetch_add` atomically increments the counter and returns its PREVIOUS value.
    // `Ordering::Relaxed` is the simplest memory ordering; it's fine for a simple counter
    // where we don't need to synchronize with other memory operations.
    // If you need the *new* value, you can just add 1 to the result of `Workspace_add`.
    COUNTER.fetch_add(1, Ordering::Relaxed) + 1
}
    #[test]
    fn test_fill_range_u32() {
        let mut data = [0u32; 5];
        fill_range(&mut data, 10..20, fast_u64_for_test);
        assert_eq!(data.len(), 5);
        for val in data {
            assert!((10..20).contains(&val));
        }
    }

    #[test]
    fn test_fill_range_u16_inclusive() {
        let mut data = [0u16; 3];
        fill_range(&mut data, 5..=7, fast_u64_for_test);
        assert_eq!(data.len(), 3);
        for val in data {
            assert!((5..=7).contains(&val));
        }
    }

    #[test]
    #[should_panic(expected = "Invalid range: Start must be included.")]
    fn test_fill_range_panic_on_non_inclusive_start() {
        let mut data = [0u32; 2];
        let range = (Bound::Excluded(5), Bound::Included(10));
        fill_range(&mut data, range, fast_u64_for_test);
    }

    #[test]
    #[should_panic(expected = "Invalid range: End must be bounded.")]
    fn test_fill_range_panic_on_unbounded_end() {
        let mut data = [0u32; 2];
        let range = 5..;
        fill_range(&mut data, range, fast_u64_for_test);
    }

    #[test]
    #[should_panic(expected = "Invalid range: End must be greater than or equal to start.")]
    fn test_fill_range_panic_on_invalid_range_order() {
        let mut data = [0u32; 2];
        let range = 10..5;
        fill_range(&mut data, range, fast_u64_for_test);
    }

    #[test]
    #[should_panic(expected = "Invalid range: Cannot generate a number from an empty range.")]
    fn test_fill_range_panic_on_empty_range_exclusive() {
        let mut data = [0u32; 2];
        let range = 5..5;
        fill_range(&mut data, range, fast_u64_for_test);
    }

    #[test]
    #[should_panic(expected = "Invalid range: End must be greater than or equal to start.")]
    fn test_fill_range_panic_on_start_greater_than_end() {
        let mut data = [0u32; 2];
        let range = 5..=4;
        fill_range(&mut data, range, fast_u64_for_test);
    }

    #[test]
    #[should_panic(expected = "Conversion failed: Cannot convert value")]
    fn test_fill_range_panic_on_out_of_range_conversion() {
        let mut data = [0u8; 2];
        let range = 0..30000; // Hodnoty mimo rozsah u8
        fill_range(&mut data, range, fast_u64);
    }