bsd4random 0.9.0

4.4BSD random number generator
Documentation
// Copyright (c) Radim Kolar 2024
// SPDX-License-Identifier: BSD-3-Clause

use super::BSD as bsd;

const TEST_SEED: u32 = 0x19610910;

const TEST_RESULTS: [i32; 5 ] = [ 1903422473, 2017226254, 1209487407, 1068869180, 1197883333 ];

/**

   test case is from rand.c in FreeBSD 4
*/
#[test]
fn seeded_pseudo_randoms() {
   let mut g = bsd::srand(TEST_SEED);
   for i in 0..TEST_RESULTS.len() {
      assert_eq!( g.rand(), TEST_RESULTS[i]);
   }
}

#[test]
fn rand_r_randoms() {
   let mut g: u32 = TEST_SEED;
   for i in 0..TEST_RESULTS.len() {
      assert_eq!( bsd::rand_r(&mut g), TEST_RESULTS[i]);
   }
}


#[test]
fn init_with_1() {
   let mut g1 = bsd::new();
   let mut g2 = bsd::srand(1);
   assert_eq!( g1.rand(), g2.rand() );
}

#[test]
fn is_send() {
   fn is_send<T: Send>() {}
   is_send::<bsd>();
}