[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Copy and initSeed: SOLUTION
From: |
Sven Thommesen |
Subject: |
Re: Copy and initSeed: SOLUTION |
Date: |
Mon, 02 Dec 1996 15:57:01 -0600 |
Benedikt Stefansson wrote:
>
> Thanks Rick for the reply,
>
> I am still in trouble though. [uniformRandom initSeed: seed] doesn't
> work because uniformRandom doesn't respond to the initSeed message.
> Apparently the initSeed message belongs to one of the
> random generators, but there are a number of them and I haven't
> been able to create an instance of one after repeated tries (e.g.
> [SWB createBegin] or somesuch).
>
> And I was also under the impression that copy should be an inherited
> method from SwarmObject, but it doesn't seem to be.
>
> If one of the hivemeisters has time to clear up this confusion I would
> appreciate it...
>
> -Benedikt.
>
Benedikt,
since nobody's jumped in from the Hive yet, I'll step up:
a) to set the seed for the supplied Uniform generator, you say
[ [ uniformRandom getGenerator] initSeed: seed];
b) to define your own generators in the same manner as the 'magical' one
supplied with Swarm, do this:
1. in modelSwarm.m, ABOVE the @implementation line, put:
id randomGenerator2, randomGenerator3;
id uniformRandom2, uniformRandom3;
2. in modelSwarm.m, in method buildObjects, you create the critters:
randomGenerator2 = [[PMMLCG1 alloc] init]; // random seed
uniformRandom2 = [[[Uniform alloc] init] setGenerator:
randomGenerator2];
randomGenerator3 = [[SWB3 alloc] init]; // another generator
uniformRandom3 = [[[Uniform alloc] init] setGenerator:
randomGenerator3];
<These are still old-style objects, hence the non-Swarmy creation.
I'll be turning the generators into proper Swarm objects as soon as
there's agreement on what methods to include ...>
3. create a file "Random.h" which you #import into any module (the .h
file or the .m file, whichever you choose) that uses these generators:
#import <random/PMMLCG.h>
#import <random/SWB.h>
#import <random/Uniform.h>
extern PMMLCG * randomGenerator2;
extern Uniform * uniformRandom2;
extern SWB * randomGenerator3;
extern Uniform * uniformRandom3;
The net effect is that these generators are globally visible in your
program, just like the one already supplied.
Enjoy!
Sven Thommesen
PS: somebody else will have to answer your question about copying
objects ...