Steffen Nurpmeso wrote in
<20220517220924.xohqc%[email protected]>:
|Joerg Sonnenberger wrote in
| <[email protected]>:
||Am Fri, May 13, 2022 at 09:43:26AM -0500 schrieb Luke Small:
||> I made a couple new versions of a new kind of arc4random_uniform-like
...
|0 bytes "do not occur", so a 32-bit RNG value "is" >=0x01FFFFFF in
|most cases for "my RNG" (of 100000 803/759/793 NOT; 776/805/793
|NOT for Linux getrandom(2)), which is a pretty high cut off.
...
/*@ lotto.cxx - output six random numbers */
#include <su/mem.h>
#include <su/random.h>
#include <sys/random.h>
//#define NYDPROF_ENABLE
//#define NYD_ENABLE
//#define NYD2_ENABLE
#include <su/code-in.h>
NSPC_USE(su)
static u32
bounded_rand(u32 range, u32 rv){
for(u32 t = -range % range;;){
if(rv >= t)
return rv % range;
log::write(log::emerg, "NOFIT");
}
}
int
main(void){
u32 uni[50], mod[50], rv;
state::create_core(NIL, (state::debug | log::debug), state::err_nopass);
su_mem_set(uni, 0, sizeof uni);
su_mem_set(mod, 0, sizeof mod);
u32 au=0;
for(u32 i = 0; i < 100000; ++i){
random::builtin_generate(&rv, sizeof rv, state::err_nopass);
//if(getrandom(&rv, sizeof rv, GRND_NONBLOCK) == -1)
// log::write(log::emerg, "getrandom(2)");
if(rv < 0x01FFFFFF)
log::write(log::info, "AU %u - 0x%X", ++au,rv);
++mod[rv % NELEM(mod)];
++uni[bounded_rand(NELEM(mod), rv)];
}
u32 unilo, modlo, unihi, modhi;
unilo = modlo = max::u32;
unihi = modhi = 0;
for(u32 i = 0; i < NELEM(uni); ++i){
unilo = get_min(unilo, uni[i]);
modlo = get_min(modlo, mod[i]);
unihi = get_max(unihi, uni[i]);
modhi = get_max(modhi, mod[i]);
log::write(log::info, "%u - %u / %u %s",
i, uni[i], mod[i], (uni[i] != mod[i] ? "!!!" : "="));
}
log::write(log::info, "MIN %u / %u, MAX %u / %u - au %u",
unilo, modlo, unihi, modhi,au);
return 0;
}
#include <su/code-ou.h>
// s-it-mode
--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)