caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Random number generator
@ 2008-09-30 13:17 Michał C
  2008-09-30 13:36 ` [Caml-list] " Till Varoquaux
  0 siblings, 1 reply; 2+ messages in thread
From: Michał C @ 2008-09-30 13:17 UTC (permalink / raw)
  To: caml-list

Hello!

Do You maybe have any idea how good is the standard RNG from random.ml  
module? I know that it's quite fast but what about the quality of  
generated numbers?

I've tried implementing various random number generators for the whole  
yesterday but I couldn't bypass ocaml's int limitations. Almost  
everything bases on unsigned integers (0..2^32-1) so despiting the  
fact my range is half of that (using Int32) I'm having troubles when  
integer overflows...

I would like to implement combined MWC (multiple with carry) algorithm  
based on 2 x 16bit mwc's. I'ts very easy (at last in c/c++ where i can  
use unsigned ints), fast and according to what I've read it's  
generating very nice random numbers.

It goes like this:

z = w= some seeds (big numbers)

z  = 36969 * (z & 65535) + (z >> 16)
w = 18000 * (w & 65535) + (w >> 16)
return ( (z << 16) + (w & 65535) )		// combining two 16 bit numbers to  
one 32 bit


but i cant think of anything by myself, i mean i could use some "abs"  
or something but i doubt it wouldn't ruin the whole algorithm.

P.S.
some time ago I promised that I will keep you informed how my ray- 
tracer will do, here it is:
http://neos1.blogspot.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-09-30 13:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-30 13:17 Random number generator Michał C
2008-09-30 13:36 ` [Caml-list] " Till Varoquaux

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).