Period of Random and big integers as iterators
- To: mathgroup at smc.vnet.net
- Subject: [mg40089] Period of Random and big integers as iterators
- From: lsczan at concentric.net
- Date: Wed, 19 Mar 2003 03:24:51 -0500 (EST)
- Reply-to: lsczan at concentric.net
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
Mathematica's documentation offers this description for the implementation of
Random:
- Random uses the Wolfram rule 30 cellular automaton generator for
integers.
- It uses a MarsagliaZaman subtractwithborrow generator for real
numbers.
Random is relatively fast. On my machine it it takes 0.321 s to
compute 10^6 (pseudo) random numbers. I am interested how long is the
period for the algorithm used by Random. If the period is, say 2^32,
then my machine would exhaust it in 2^32/10^6 0.321 / 60 = 22.9781
minutes. I made an experiment that apparently exposes some limitations
of Mathematica.
In[1]:=
SeedRandom[5]
In[2]:=
x = Random[]
Out[2]=
0.786599
In[3]:=
count = 1;
In[4]:=
While[True,
count++;
If[Random[]== x, Print[count]; Break[]]]
Internal counter overflow.
Some expression evaluations may not run to their
final fixed points. Try redoing your computation
on a 64-bit enhanced version of Mathematica.
It looks like While can go through a limited number of loops.
Similarly, I got the following error for Do.
In[5]:=
Do[1, {2147483648}]
Do::iterb: Iterator {2147483648} does not have appropriate bounds.
Apparently, the maximum value for the iterator is 2^31-1 = 2147483647,
because
Do[1, {2147483648-1}]
actually works.
Does anybody know:
1. What is the period for Random[]?
2. Is it possible to use big integers as iterators in Mathematica?
Thanks,
LS