[Newbies] Randomness

Bert Freudenberg bert at freudenbergs.de
Thu Apr 7 12:23:03 UTC 2011


If you are following trunk updates, yes. Otherwise you would have to wait for the next release.

- Bert -

On 07.04.2011, at 14:20, michael rice wrote:

> And I can acquire the new behavior by updating Squeak?
> 
> Michael
> 
> --- On Thu, 4/7/11, Bert Freudenberg <bert at freudenbergs.de> wrote:
> 
> From: Bert Freudenberg <bert at freudenbergs.de>
> Subject: Re: [Newbies] Randomness
> To: "A friendly place to get answers to even the most basic questions about Squeak." <beginners at lists.squeakfoundation.org>
> Date: Thursday, April 7, 2011, 6:19 AM
> 
> The new behavior is that you get a different stream of random numbers each time you start the image. Or at least it's really really unlikely you get the same sequence again. 
> 
> - Bert -
> 
> On 07.04.2011, at 02:54, michael rice wrote:
> 
>> 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?
>> 
>> Michael
>> 
>> --- On Wed, 4/6/11, David T. Lewis <lewis at mail.msen.com> wrote:
>> 
>> From: David T. Lewis <lewis at mail.msen.com>
>> Subject: Re: [Newbies] Randomness
>> To: "A friendly place to get answers to even the most basic questions about Squeak." <beginners at lists.squeakfoundation.org>
>> Date: Wednesday, April 6, 2011, 8:35 PM
>> 
>> I made the update in Squeak trunk similar to the Etoys image, but used
>> the existing seed generator in Random>>initialize on the theory that if
>> the generator is good enough for a new Random, it should be good enough
>> for an existing one too ;)
>> 
>> Michael, thanks for spotting the problem.
>> 
>> Dave
>> 
>> On Tue, Apr 05, 2011 at 01:16:31PM +0200, Bert Freudenberg wrote:
>> > 
>> > On 05.04.2011, at 02:32, Levente Uzonyi wrote:
>> > 
>> > > On Mon, 4 Apr 2011, michael rice wrote:
>> > > 
>> > >> I forgot to mention, I'm using the random number tile and scripting. Does that make it more difficult?
>> > > 
>> > > Not really, RandomNumberTile uses the global random number generator of Collection. I don't know how/why is it serialized/restored
>> > 
>> > 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
>> > 
>> > startUp
>> >     RandomForPicking seed: Time totalSeconds hash asFloat.
>> > 
>> > IMHO we should adopt something like this for trunk (maybe with your "more" random approach below). 
>> > 
>> > - Bert -
>> > 
>> > > but here's a method which should help:
>> > > 
>> > > RandomNumberTile >> #comeFullyUpOnReload: smartRefStream
>> > > 
>> > >     | seed |
>> > >     [
>> > >         seed := (Time millisecondClockValue bitAnd: 16r3FFFFFFF) bitXor: self hash.
>> > >         seed := seed bitXor: (Time totalSeconds bitAnd: 16r3FFFFFFF).
>> > >         seed := seed bitXor: 16r3FFFFFFF atRandom.
>> > >         seed = 0 ] whileTrue. "Try again if ever get a seed = 0"
>> > >     Collection mutexForPicking critical: [
>> > >         Collection randomForPicking seed: seed ].
>> > >     ^super comeFullyUpOnReload: smartRefStream
>> > > 
>> > > 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.
>> > > 
>> > > 
>> > > Levente
>> > > 
>> > >> 
>> > >> Michael
>> > >> 
>> > >> --- On Mon, 4/4/11, Levente Uzonyi <leves at elte.hu> wrote:
>> > >> 
>> > >> From: Levente Uzonyi <leves at elte.hu>
>> > >> Subject: Re: [Newbies] Randomness
>> > >> To: "A friendly place to get answers to even the most basic questions about Squeak." <beginners at lists.squeakfoundation.org>
>> > >> Date: Monday, April 4, 2011, 8:08 PM
>> > >> 
>> > >> On Mon, 4 Apr 2011, michael rice wrote:
>> > >> 
>> > >>> 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?
>> > >> 
>> > >> 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.
>> > >> 
>> > >> 
>> > >> Levente
>> > 
> 
> 
> 
> 
> 
> -----Inline Attachment Follows-----



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20110407/8ced166c/attachment-0001.htm


More information about the Beginners mailing list