Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #26947
| From | C G Montgomery <cgm@physics.utoledo.edu> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Multiply With Carry random generators |
| Date | 2013-11-25 13:46 -0500 |
| Organization | the wetware works |
| Message-ID | <l705uj$44i$1@dont-email.me> (permalink) |
| References | <5292ab81$0$3214$e4fe514c@dreader36.news.xs4all.nl> |
Albert van der Horst albert@spenarnc.xs4all.nl wrote: > Looking into random number generators lately, mhx mentioned the > diehard program. > This was written by Marsaglia and with his linux version of the program > he distributes a file mwcp.ps explaining the Multiply With Carry random > generators. > > They are simple enough to be typed in by heart whenever you need one, > yet they have respectable periods of 2^64 for 32-bits and 2^128 for > 64 bits. Where Marsaglia promotes them they must be pretty good. > The nice thing are the constants. They are small enough to remember. > The multipliers are from wikipedia. > Like the congruentual generators they are simpler in Forth than in other > languages, especially given the double precision wordsets. > ...some [untested] code snipped... It turns out that both Fortran and C encounter some complexities in getting 64-bit randoms from MWC algorithms. It's certainly simple in Forth; you do just what I posted years ago with suitable choices for 64-bit systems, which I didn't cover way back then. For possible convenience I'm including a loadable file. If you really want 64-bit randoms on a smaller system, just run separate generators for pieces of the value you need. regards cgm \ 64-bit pseudo-random number generators \ Charles G. Montgomery Nov2012 DEFER rand \ set to choice of generators HEX \ multiply-with-carry (George Marsaglia) 400000000000001 Constant rmult \ 2^58+1 2VARIABLE rloc 3456123456123456 4567890987654321 rloc 2! \ Marsaglia's values : mwc ( -- u ) rloc 2@ rmult UM* ROT 0 D+ OVER rloc 2! ; ' mwc is rand \ recommended rmult values for other cell sizes \ 32 bits: 7A3FFD4B 7549D83B 70DCB7DC 6A364C22 62AFDC7A \ 16 bits: 65E8 61BF 62DC 6594 6363 5E9B \ 8 bits: 65FF 56FF 68FF 317F \ periods ~2^29 for 16 bits, ~2^58 for 32 bits, ~2^121 for 64 bits \ linear congruential multiplier (with Marsaglia's constants) 19BAFFBED CONSTANT rgen 12D687 CONSTANT rplus VARIABLE rseed 12345678 rseed ! : lcm ( -- u ) rseed @ rgen um* drop rplus + dup rseed ! ; \ ====end of file========
Back to comp.lang.forth | Previous | Next — Previous in thread | Find similar | Unroll thread
Multiply With Carry random generators albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-11-25 01:44 +0000 Re: Multiply With Carry random generators mhx@iae.nl - 2013-11-25 10:40 -0800 Re: Multiply With Carry random generators C G Montgomery <cgm@physics.utoledo.edu> - 2013-11-25 13:46 -0500
csiph-web