Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Period of Random and big integers as iterators

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40097] Re: Period of Random and big integers as iterators
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Thu, 20 Mar 2003 03:33:15 -0500 (EST)
  • Organization: Universitaet Leipzig
  • References: <b59a5b$sbb$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

a) a Marsaglia­Zaman generator with 24 bit mantissas has a
   period of 2^144. If you assume, that a single test in your
   loop take 10^(-4) seconds your method for finding the period will
   run only 7 * 10^31 years and I recommend a very robust and stable
   computer for this experiment. Send me a mail if it is finished !
   
b) you can use For[] to use iterators larger 
   than a 32 bit signed integer. 

   For[i = 2^31 - 1, i < 2147483669, i++, 
     If[Mod[i, 2] == 0, Print[i]]; 1];

   The larger speed of a Do[]
   function comes form the usage of machine integers

Regards
  Jens

lsczan at concentric.net wrote:
> 
> 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 Marsaglia­Zaman subtract­with­borrow 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


  • Prev by Date: Mathematica Developer Conference in April 2003
  • Next by Date: RE: RE: Increase in efficiency with Module
  • Previous by thread: Period of Random and big integers as iterators
  • Next by thread: Trouble with an iterative function