Gotcha! Or at least, I can see a flaw here in ChucK's randomizers: there is only one of them! My immediate reaction to seeing your code was that it ought to be simplified to this:<div><br></div><div><div>while (1)</div>
<div>{</div><div>    Std.srand(1200); //set your seed</div><div>    for(0 => int i; i < 8; i++) </div><div>    {</div><div>        <<<Std.rand2( 1 , 1000 )>>>;</div><div>    }</div><div>    <<<"--------------", "we always get the same numbers" >>>;</div>
<div>    2::second=>now;</div><div>    </div><div>}</div><div><br></div><div>But this won't work if you use the randomizer elsewhere in your code. if someone calls Std.rand2() before the loop above has finished, the random sequence will be corrupted. It will work here though, since there is no wait statement inside the for loop, but I suspect Lars's code is more complicated than this.</div>
<div><br></div><div>Other programming languages will usually have some kind of randomizer object (e.g. "Random" in Java or the result of the seed function in PovRAY), that you instantiate with a seed (if you want) and then use independent from other random instances. If we had that you could write this code:</div>
<div><br></div><div>0 => int resetSeed;</div><div>Std.makeRandomizer() => Random r;</div><div>while (1)</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>if (resetSeed) {</div><div><span class="Apple-tab-span" style="white-space:pre">             </span>r.srand(1200); //set your seed</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>}</div><div>    for(0 => int i; i < 8; i++) </div><div>    {</div><div>        <<<r.rand2( 1 , 1000 )>>>;</div><div>    }</div><div>
    <<<"--------------", "we always get the same numbers" >>>;</div><div>    2::second=>now;</div><div>    </div><div>}</div><div><br></div><div>...without clashing with other usage of randomizers (I made up some function and class names).</div>
<div><br></div><div>Was it something like this that you ran into, Lars?</div><div><br></div><div>/Stefan</div><div class="gmail_quote">2010/9/11 Kassen <span dir="ltr"><<a href="mailto:signal.automatique@gmail.com">signal.automatique@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hey, Lars!<div><br></div><div>I'm not Stephan, but I'm still a bit confused as well so I thought I'd answer anyway.</div>
<div><br><div><div class="gmail_quote"><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(96, 144, 16)">
<span style="color:#000000">Std.srand(</span><span style="color:#d48010">1200</span><span style="color:#000000">); </span>//set your seed</div>
</div></div></div></blockquote><div><br></div></div><div>Looks fine</div><div class="im"><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">
<div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(64, 64, 64)"><span style="color:#000000">    <<<</span>"--------------"<span style="color:#000000">,</span> "we always get the same numbers" <span style="color:#000000">>>>;</span></div>

</div></div></div></blockquote><div><br></div></div><div>That's what we'd expect, yes. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">

<div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">Hope this helps!</div><p style="margin-top:0px;margin-right:0px;margin-bottom:12px;margin-left:0px">

</p></div></div></div></blockquote><div> Well.... no, not really.</div><div><br></div><div>What happens if you don't set the seed with srand(), do you still get the same numbers? As I understand things now you should get exactly what you are looking for by simply not setting the seed in line 1. Could you verify that by not setting the seed at all you get different numbers each time you run your program? If not we have a bug. I seem to remember there was a issue like that on Windows, which might be caused by Windows (last time I looked) not having the "storage" of OS-event based random numbers that Unix typically uses; that might be the cause. That's no excuse though; as we are not trying to secure nuclear missiles (I hope!) something like the time in ms should yield a perfectly serviceable seed at VM startup.</div>

<div><br></div><div>Yours,</div><div>Kas.</div></div></div></div>
<br>_______________________________________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Release me, insect, or I will destroy the Cosmos!<br>
</div>