Re: Re: Using The Random Function to predict Things
- To: mathgroup at smc.vnet.net
- Subject: [mg63034] Re: [mg63004] Re: Using The Random Function to predict Things
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Sun, 11 Dec 2005 04:57:24 -0500 (EST)
- References: <dnbn04$5qv$1@smc.vnet.net> <200512101103.GAA29413@smc.vnet.net> <01BADD95-983F-4969-84BF-00BAD605D411@mimuw.edu.pl> <A89D6ED2-C1B1-4EAA-9DFB-8D263F6A4DD6@mimuw.edu.pl>
- Sender: owner-wri-mathgroup at wolfram.com
I have to make more corrections. Firstly, I meant, of course , "until successive k heads come up". And secondly, one should start nesting with a "digital coin throw" Random[Integer] rather than with 0, so the correct code is: simulate[k_]:=NestWhileList[Random[Integer]&,Random[Integer],Plus[##] =!=k&,k] Andrzej On 11 Dec 2005, at 10:54, Andrzej Kozlowski wrote: > On 11 Dec 2005, at 10:46, Andrzej Kozlowski wrote: > > >> A simple way to simulate tossing a coin until three heads come up is: >> >> >> simulate[k_]:=NestWhileList[Random[Integer]&,0,Plus[##]=!=k&,k] > > > I meant "until k heads come up". > > > Andrzej Kozlowski > > > >> >> >> On 10 Dec 2005, at 20:03, Peter Pein wrote: >> >>> 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. >>> >> >> This answer is, of course, correct. In fact the answer to the >> question "how many flips of a coin are needed on the average to >> get any specified pattern" is well known and due to A. D. Solvev. >> The whole problem is solved in detail in Knuth's book "Concrete >> Mathematics" ( see particularly page 394 in the chapter "Discrete >> Probability"). >> >> A simple way to simulate tossing a coin until three heads come up is: >> >> >> simulate[k_]:=NestWhileList[Random[Integer]&,0,Plus[##]=!=k&,k] >> >> For example: >> simulate[5] >> >> >> {0,1,0,1,1,0,1,0,1,1,0,1,0,1,1,1,0,1,1,0,0,1,0,1,0,0,1,0,0,1,0,1,0,0, >> 0,0,0,1,\ >> 1,1,0,0,0,1,1,1,0,1,1,0,0,0,0,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,0,0,1,0,1 >> ,0,0,1,0,\ >> 0,1,1,0,1,1,0,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,1,1,0,0,1,1,1,1,0,0,1,0 >> ,1,0,0,0,\ >> 1,1,1,0,0,1,1,1,1,0,1,1,0,0,1,1,1,1,1} >> >> >> Andrzej Kozlowski >
- References:
- Re: Using The Random Function to predict Things
- From: Peter Pein <petsie@dordos.net>
- Re: Using The Random Function to predict Things