[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ProgSoc] Randomisation
> > I've heard tell of generators which read the system things like space
> > between interrupts (keyboard etc) and small variations in the system
> > clock ticks to try to randomise the values a little more. I suggest a
> > quick look on the web for stuff on pseudo-random number generators and
> > check out how big their sequences are.
>
> Or measure the electrical noise from system components?
If you are on a linux system then you just open the /dev/random device
or else the /dev/urandom device. In the source code of this device is
a long comment explaining how it works, how random it really is, and
what sort of things you might want to use it for.
In simple terms, /dev/random is slower and less predictable while
/dev/urandom is faster and slightly easier to predict but still pretty
damn close to total chaos.
> > "If you want to generate a random integer between 1
> > and 10, you should always do it by
> >
> > j=1+(int) (10.0*rand()/(RAND_MAX+1.0));
> >
> > and never by anything resembling
> >
> > j=1+((int) (1000000.0*rand()) % 10);
> >
> > (which uses lower-order bits)."
>
> In both cases, depending on the RNG, you could overflow first. (But not
> a problem with the standard unix rand().)
So long as the overflow doesn't cause an interrupt or float exception,
it doesn't really matter (he thinks...) I have noticed a massive difference
in randomness when using modulo by prime as against modulo by power of 2.
If you can make your desired range something prime then modulo starts to
work a whole lot better.
- Tel
--
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to progsoc-request@nospam.progsoc.uts.edu.au.
If you are having trouble, ask owner-progsoc@nospam.progsoc.uts.edu.au for help.
This list is archived at <http://www.progsoc.uts.edu.au/lists/progsoc/>