|
@@ -24,7 +24,7 @@ use crate::{
|
|
|
platform::{self, types::*, Pal, Sys},
|
|
|
};
|
|
|
|
|
|
-mod lcg48;
|
|
|
+mod rand48;
|
|
|
mod random;
|
|
|
mod sort;
|
|
|
|
|
@@ -245,8 +245,8 @@ pub extern "C" fn div(numer: c_int, denom: c_int) -> div_t {
|
|
|
|
|
|
#[no_mangle]
|
|
|
pub unsafe extern "C" fn drand48() -> c_double {
|
|
|
- let new_xsubi_value = lcg48::generator_step(&mut lcg48::DEFAULT_XSUBI);
|
|
|
- lcg48::f64_from_x(new_xsubi_value)
|
|
|
+ let new_xsubi_value = rand48::generator_step(&mut rand48::DEFAULT_XSUBI);
|
|
|
+ rand48::f64_from_x(new_xsubi_value)
|
|
|
}
|
|
|
|
|
|
// #[no_mangle]
|
|
@@ -261,8 +261,8 @@ pub extern "C" fn ecvt(
|
|
|
|
|
|
#[no_mangle]
|
|
|
pub unsafe extern "C" fn erand48(xsubi: *mut c_ushort) -> c_double {
|
|
|
- let new_xsubi_value = lcg48::generator_step(&mut *(xsubi as *mut [c_ushort; 3]));
|
|
|
- lcg48::f64_from_x(new_xsubi_value)
|
|
|
+ let new_xsubi_value = rand48::generator_step(&mut *(xsubi as *mut [c_ushort; 3]));
|
|
|
+ rand48::f64_from_x(new_xsubi_value)
|
|
|
}
|
|
|
|
|
|
#[no_mangle]
|
|
@@ -399,8 +399,8 @@ pub unsafe extern "C" fn initstate(seed: c_uint, state: *mut c_char, size: size_
|
|
|
|
|
|
#[no_mangle]
|
|
|
pub unsafe extern "C" fn jrand48(xsubi: *mut c_ushort) -> c_long {
|
|
|
- let new_xsubi_value = lcg48::generator_step(&mut *(xsubi as *mut [c_ushort; 3]));
|
|
|
- lcg48::i32_from_x(new_xsubi_value)
|
|
|
+ let new_xsubi_value = rand48::generator_step(&mut *(xsubi as *mut [c_ushort; 3]));
|
|
|
+ rand48::i32_from_x(new_xsubi_value)
|
|
|
}
|
|
|
|
|
|
#[no_mangle]
|
|
@@ -450,15 +450,15 @@ pub extern "C" fn labs(i: c_long) -> c_long {
|
|
|
#[no_mangle]
|
|
|
pub unsafe extern "C" fn lcong48(param: *mut c_ushort) {
|
|
|
// Set DEFAULT_XSUBI buffer from elements 0-2
|
|
|
- let xsubi_value = lcg48::u48_from_ushort_arr3(&*(param as *const [c_ushort; 3]));
|
|
|
- lcg48::DEFAULT_XSUBI = lcg48::ushort_arr3_from_u48(xsubi_value);
|
|
|
+ let xsubi_value = rand48::u48_from_ushort_arr3(&*(param as *const [c_ushort; 3]));
|
|
|
+ rand48::DEFAULT_XSUBI = rand48::ushort_arr3_from_u48(xsubi_value);
|
|
|
|
|
|
// Set multiplier from elements 3-5
|
|
|
- lcg48::A = lcg48::u48_from_ushort_arr3(&*(param.offset(3) as *const [c_ushort; 3]));
|
|
|
+ rand48::A = rand48::u48_from_ushort_arr3(&*(param.offset(3) as *const [c_ushort; 3]));
|
|
|
|
|
|
/* Set addend from element 6. Note that c_ushort may be more than 16
|
|
|
* bits, thus the cast. */
|
|
|
- lcg48::C = *param.offset(6) as u16;
|
|
|
+ rand48::C = *param.offset(6) as u16;
|
|
|
}
|
|
|
|
|
|
#[repr(C)]
|
|
@@ -496,8 +496,8 @@ pub extern "C" fn lldiv(numer: c_longlong, denom: c_longlong) -> lldiv_t {
|
|
|
|
|
|
#[no_mangle]
|
|
|
pub unsafe extern "C" fn lrand48() -> c_long {
|
|
|
- let new_xsubi_value = lcg48::generator_step(&mut lcg48::DEFAULT_XSUBI);
|
|
|
- lcg48::u31_from_x(new_xsubi_value)
|
|
|
+ let new_xsubi_value = rand48::generator_step(&mut rand48::DEFAULT_XSUBI);
|
|
|
+ rand48::u31_from_x(new_xsubi_value)
|
|
|
}
|
|
|
|
|
|
#[no_mangle]
|
|
@@ -650,14 +650,14 @@ pub extern "C" fn mkstemps(name: *mut c_char, suffix_len: c_int) -> c_int {
|
|
|
|
|
|
#[no_mangle]
|
|
|
pub unsafe extern "C" fn mrand48() -> c_long {
|
|
|
- let new_xsubi_value = lcg48::generator_step(&mut lcg48::DEFAULT_XSUBI);
|
|
|
- lcg48::i32_from_x(new_xsubi_value)
|
|
|
+ let new_xsubi_value = rand48::generator_step(&mut rand48::DEFAULT_XSUBI);
|
|
|
+ rand48::i32_from_x(new_xsubi_value)
|
|
|
}
|
|
|
|
|
|
#[no_mangle]
|
|
|
pub unsafe extern "C" fn nrand48(xsubi: *mut c_ushort) -> c_long {
|
|
|
- let new_xsubi_value = lcg48::generator_step(&mut *(xsubi as *mut [c_ushort; 3]));
|
|
|
- lcg48::u31_from_x(new_xsubi_value)
|
|
|
+ let new_xsubi_value = rand48::generator_step(&mut *(xsubi as *mut [c_ushort; 3]));
|
|
|
+ rand48::u31_from_x(new_xsubi_value)
|
|
|
}
|
|
|
|
|
|
#[no_mangle]
|
|
@@ -824,17 +824,17 @@ pub unsafe extern "C" fn realpath(pathname: *const c_char, resolved: *mut c_char
|
|
|
|
|
|
#[no_mangle]
|
|
|
pub unsafe extern "C" fn seed48(seed16v: *mut c_ushort) -> *mut c_ushort {
|
|
|
- lcg48::reset_a_and_c();
|
|
|
+ rand48::reset_a_and_c();
|
|
|
|
|
|
// Stash current DEFAULT_XSUBI value in SEED48_XSUBI
|
|
|
- lcg48::SEED48_XSUBI = lcg48::DEFAULT_XSUBI;
|
|
|
+ rand48::SEED48_XSUBI = rand48::DEFAULT_XSUBI;
|
|
|
|
|
|
// Set DEFAULT_XSUBI from the argument provided
|
|
|
- let xsubi_value = lcg48::u48_from_ushort_arr3(&*(seed16v as *const [c_ushort; 3]));
|
|
|
- lcg48::DEFAULT_XSUBI = lcg48::ushort_arr3_from_u48(xsubi_value);
|
|
|
+ let xsubi_value = rand48::u48_from_ushort_arr3(&*(seed16v as *const [c_ushort; 3]));
|
|
|
+ rand48::DEFAULT_XSUBI = rand48::ushort_arr3_from_u48(xsubi_value);
|
|
|
|
|
|
// Return the stashed value
|
|
|
- lcg48::SEED48_XSUBI.as_mut_ptr()
|
|
|
+ rand48::SEED48_XSUBI.as_mut_ptr()
|
|
|
}
|
|
|
|
|
|
#[no_mangle]
|
|
@@ -928,13 +928,13 @@ pub unsafe extern "C" fn srand(seed: c_uint) {
|
|
|
|
|
|
#[no_mangle]
|
|
|
pub unsafe extern "C" fn srand48(seedval: c_long) {
|
|
|
- lcg48::reset_a_and_c();
|
|
|
+ rand48::reset_a_and_c();
|
|
|
|
|
|
/* Set the high 32 bits of the 48-bit X_i value to the lower 32 bits
|
|
|
* of the input argument, and the lower 16 bits to 0x330e, as
|
|
|
* specified in POSIX. */
|
|
|
let xsubi_value = (u64::from(seedval as u32) << 16) | 0x330e;
|
|
|
- lcg48::DEFAULT_XSUBI = lcg48::ushort_arr3_from_u48(xsubi_value);
|
|
|
+ rand48::DEFAULT_XSUBI = rand48::ushort_arr3_from_u48(xsubi_value);
|
|
|
}
|
|
|
|
|
|
#[no_mangle]
|