<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">So it was a problem? The old behavior was: if I saved a project and quit the image without saving it, the next time I bought up the image and loaded the project I would get the same stream of random numbers. What is the new behavior?<br><br>Michael<br><br>--- On <b>Wed, 4/6/11, David T. Lewis <i><lewis@mail.msen.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: David T. Lewis <lewis@mail.msen.com><br>Subject: Re: [Newbies] Randomness<br>To: "A friendly place to get answers to even the most basic questions about Squeak." <beginners@lists.squeakfoundation.org><br>Date: Wednesday, April 6, 2011, 8:35 PM<br><br><div class="plainMail">I made the update in Squeak trunk similar to the Etoys image, but used<br>the existing seed generator in Random>>initialize on the
theory that if<br>the generator is good enough for a new Random, it should be good enough<br>for an existing one too ;)<br><br>Michael, thanks for spotting the problem.<br><br>Dave<br><br>On Tue, Apr 05, 2011 at 01:16:31PM +0200, Bert Freudenberg wrote:<br>> <br>> On 05.04.2011, at 02:32, Levente Uzonyi wrote:<br>> <br>> > On Mon, 4 Apr 2011, michael rice wrote:<br>> > <br>> >> I forgot to mention, I'm using the random number tile and scripting. Does that make it more difficult?<br>> > <br>> > Not really, RandomNumberTile uses the global random number generator of Collection. I don't know how/why is it serialized/restored<br>> <br>> It is not stored in the project. But in trunk, the seed does not get re-initialized when starting up. In the Etoys image, Collection class has a startUp method<br>> <br>> startUp<br>> RandomForPicking seed: Time totalSeconds hash asFloat.<br>>
<br>> IMHO we should adopt something like this for trunk (maybe with your "more" random approach below). <br>> <br>> - Bert -<br>> <br>> > but here's a method which should help:<br>> > <br>> > RandomNumberTile >> #comeFullyUpOnReload: smartRefStream<br>> > <br>> > | seed |<br>> > [<br>> > seed := (Time millisecondClockValue bitAnd: 16r3FFFFFFF) bitXor: self hash.<br>> > seed := seed bitXor: (Time totalSeconds bitAnd: 16r3FFFFFFF).<br>> > seed := seed bitXor: 16r3FFFFFFF atRandom.<br>> > seed = 0 ] whileTrue. "Try again if ever get a seed = 0"<br>> > Collection mutexForPicking critical: [<br>> > Collection randomForPicking
seed: seed ].<br>> > ^super comeFullyUpOnReload: smartRefStream<br>> > <br>> > It's drawback is that it will reseed the rng for every RandomNumberTile. The best solution would be if Etoys would use a custom Random instance or a subclass where this is done by default.<br>> > <br>> > <br>> > Levente<br>> > <br>> >> <br>> >> Michael<br>> >> <br>> >> --- On Mon, 4/4/11, Levente Uzonyi <<a ymailto="mailto:leves@elte.hu" href="/mc/compose?to=leves@elte.hu">leves@elte.hu</a>> wrote:<br>> >> <br>> >> From: Levente Uzonyi <<a ymailto="mailto:leves@elte.hu" href="/mc/compose?to=leves@elte.hu">leves@elte.hu</a>><br>> >> Subject: Re: [Newbies] Randomness<br>> >> To: "A friendly place to get answers to even the most basic questions about Squeak." <<a ymailto="mailto:beginners@lists.squeakfoundation.org"
href="/mc/compose?to=beginners@lists.squeakfoundation.org">beginners@lists.squeakfoundation.org</a>><br>> >> Date: Monday, April 4, 2011, 8:08 PM<br>> >> <br>> >> On Mon, 4 Apr 2011, michael rice wrote:<br>> >> <br>> >>> I just noticed that when I load a morphic project I get the same stream of random numbers each time. Is there a simple way to install a new different random seed each time the project is loaded?<br>> >> <br>> >> If you serialize the Random object, then it will have the same state when it's restored. I guess you should create a subclass of Random, which implements #comeFullyUpOnReload:. That method can reinitialize the seed of the random number generator. You may want to check UUIDGenerator >> #makeSeed if you don't know how to get a good seed for your rng.<br>> >> <br>> >> <br>> >> Levente<br>> <br>>
_______________________________________________<br>> Beginners mailing list<br>> <a ymailto="mailto:Beginners@lists.squeakfoundation.org" href="/mc/compose?to=Beginners@lists.squeakfoundation.org">Beginners@lists.squeakfoundation.org</a><br>> <a href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br>_______________________________________________<br>Beginners mailing list<br><a ymailto="mailto:Beginners@lists.squeakfoundation.org" href="/mc/compose?to=Beginners@lists.squeakfoundation.org">Beginners@lists.squeakfoundation.org</a><br><a href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br></div></blockquote></td></tr></table>