multithreading - Is this way of generating random numbers safe and valid? -
i doing recreational low-level programming other day, , somewhere in code thing emerged (using pseudocode):
cointoss program
char out = '0'; void thread(){ out = '1';} int main(){ // creates thread run function provided // main() not wait thread finish runinownthread(thread); printr("%d", out); return 0; }
now in our shell run cointoss
program x
number of times , end this:
0011011100001000
which can convert decimal , random number
my question not whether efficient way of creating random number more can tell if end result random enough use
no, using race condition not way generate random numbers. result nondeterministic, result heavily weighted towards 1 outcome.
if don't care values being heavily weighted (that random enough you), go ahead.
Comments
Post a Comment