MathGroup Archive 2002

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

Search the Archive

Re: something fishy in mathematica random generation?

  • To: mathgroup at
  • Subject: [mg33143] Re: [mg33097] something fishy in mathematica random generation?
  • From: Daniel Lichtblau <danl at>
  • Date: Tue, 5 Mar 2002 03:08:49 -0500 (EST)
  • References: <>
  • Sender: owner-wri-mathgroup at

KIMIC Weijnitz Peter wrote:
> I hope someone can explain this.
> A characteristic of a truly random behavior is that events tend to
> cluster.
> E.g. a  molecular collision is more likely to occur just after the most
> recent collision.
> or, in a bit stream, a bit error is more likely to occur just after the
> most recent error if the errors are generated by random noise.
> I simulated this with a generated vector with ones and zeroes with a
> given probability using Random and RandomSeed in Mathematica 3.01. and I
> found something peculiar with the random generation in Mathemathica,
> Just run these lines and see for yourself:
> SeedRandom[1111111 ] (*change this number to get another random
> sequence*)
> vec1=Table[Random[Real,{0,1000}],{10^6}];              (*reduce this
> vector length if you get memory problem*)
> vec2=Map[If[#<44,1,0]&,vec1];                          (*threshhold for
> ones*)
> ones=Flatten[Position[vec2,1]];                        (*vector of index
> positions for ones *)
> Length[ones]/10.^6                                     (*check for the
> average of ones*)
> plotvec=Map[Length,Split[Sort[Drop[ones-RotateRight[ones,1],1]]]];
> (*subtracts ones[[i]]-ones[[i+1]]*)
> ListPlot[Log[plotvec],PlotRange->All]
> It is the plot that seems a bit strange to me, I get the expected
> decreasing exponential behavior in
> the probability of the interval length between ones.
> But, (this is the question) in all different simulations I have made
> with different RandomSeed[], average
> of ones, different vector length, the interval of 24 have a lower
> frequency than expected.
> If this behavior persists when you test, what is the reason?
> If not, why do I get it, I have tried it on two computers.
> hehe.. if you reverse 24 you get 42???
> Peter W

I once responded to an equivalent question in this news group:

In that case as well something bad happened in the 24th bin which was
(as in your case) reliably under where it should have been.

The upshot is that this appears to be a hazard of subtract-with-borrow
based random generators, which is what is used to generate random
machine doubles. This defect does not appear to afflict the cellular
automaton generator used to form random integers smaller than 2^30.
Hence to ellude it in your example you might do as below.

vec1 = Table[Random[Integer,1000],{10^6}]; (* generate integer instead
of real *)
vec2 = Map[If[#<=44,1,0]&, vec1];
ones = Flatten[Position[vec2,1]];
plotvec = Map[Length, Split[Sort[Drop[ones-RotateRight[ones,1],1]]]];
ListPlot[Log[plotvec], PlotRange->All]

For further information, more general workarounds, etc. I defer to my
5/00 post at the URL above.

By the way, I don't think clustering is equivalent to "a bit error is
more likely to occur just after the most recent error if the errors are
generated by random noise."

Daniel Lichtblau
Wolfram Research

  • Prev by Date: Re: creating functions with variable number of options
  • Next by Date: Quadratic non-linear ODE.
  • Previous by thread: something fishy in mathematica random generation?
  • Next by thread: Parameters