       Re: Using The Random Function to predict Things

• To: mathgroup at smc.vnet.net
• Subject: [mg63004] Re: Using The Random Function to predict Things
• From: Peter Pein <petsie at dordos.net>
• Date: Sat, 10 Dec 2005 06:03:34 -0500 (EST)
• References: <dnbn04\$5qv\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```mathuser schrieb:
> Hi there friends...
> I used this line of code "typicalList = Table[Random[Integer], {50}]" and got this result...
>
> {1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, \
> 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1}
>
> By generating a few more of these random lists, I'm to predict a similiar situation: such as how long i would expect to wait for 3 heads in a coin tossing competition...
>
> any suggestion or help as to what code i could use to do this?
>
> thanks a lot guys
>
Hi,

in this kind of sequence you've got 2^k possibilities of k subsequent
numbers. One of them consits of k times the one. As 1 and 0 occur with
the same probability, one would expect to wait on average 2(2^k-1)
"tosses" of digits.

I'll code it using bitsequences. We have to shift through a random
bitstream until a "window" of length k contains only ones, that is: its
value is 2^k-1:

WaitFor=Compile[{{k,_Integer}},
Module[{n, x, t = 2^k - 1},
For[n = k; x = Table[Random[Integer], {k}].(2^Range[0, k - 1]),
x =!= t,
n++,
x = BitAnd[x + x + Random[Integer], t]
];
n],
{{n | x | t, _Integer}}];

Note that this works only for 1<= k < Log[2, \$MaxMachineInteger + 1].

Let's start the experiment:

how long do we have to wait for a run of 1,2,..8 ones?

N@Mean[Table[WaitFor[#],{10^4}]]&/@Range
--> {1.9927,5.9813,13.859,30.1861,62.3696,126.264,253.831,506.15}

Now, check my hypothesis:
Round[%]-Table[2(2^k-1),{k,8}]
--> {0, 0, 0, 0, 0, 0, 0, -4}

looks good, but the empirical value for k=8 differs clearly. So repeat
the experiment until the hypothesis turns out to be plausible (I once
studied engineering too ;-) )

Mean[Table[WaitFor,{10^6}]]//N
--> 510.346

Well, this is an acceptable outcome :-))

Peter

```

• Prev by Date: Re: Solve Limitations
• Next by Date: Re: exponential diophantine equations
• Previous by thread: Re: Using The Random Function to predict Things
• Next by thread: Re: Re: Using The Random Function to predict Things