We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Partial RandomSeed()
Page Index Toggle Pages: 1
Partial RandomSeed() (Read 526 times)
Partial RandomSeed()
Dec 10th, 2007, 9:52am
 
Hi,

Is there a way to use randomSeed only on specific parts of program? Or rather could I introduce some sporadic instances of "pure randomness" and still use randomSeed for the rest?

Thanx
Re: Partial RandomSeed()
Reply #1 - Dec 10th, 2007, 10:47am
 
You can create separate Random objects to use in specific areas, and give them set seeds: http://java.sun.com/j2se/1.4.2/docs/api/java/util/Random.html
Re: Partial RandomSeed()
Reply #2 - Dec 10th, 2007, 10:46pm
 
Thanks John, that looks like just what I need. Sadly though my understanding of pure Java is not good enough to make out how to go about it from reading the javadoc. If anybody could give me a hint on how this would look in processing code I would be very grateful.
Re: Partial RandomSeed()
Reply #3 - Dec 10th, 2007, 11:37pm
 
It would look something like:

Code:
Random myRandom(123456);
int a=myRandom.nextInt(1000); // a random number from 0-1000

Random myOtherRandom(123456);
int b=myOtherRandom.nextInt(1000); // b==a

int c=random(1000); // a completely unrelated number, since this uses processing' built-in random source.
Re: Partial RandomSeed()
Reply #4 - Dec 11th, 2007, 9:34pm
 
Thanks again John, that will be really helpful Smiley
Re: Partial RandomSeed()
Reply #5 - Jan 23rd, 2008, 7:26pm
 
Hey,

I think I have the same problem like Tor.
I need for only 2 variables a random with randomSeed. After this I need a variable with changes randomly. There are all in a for-loop, like this:

draw(){
for (0 to 2){
 float a = random(0,1); //this I need randomly changes
 float x = random(1,5); //should be the same each time
 float y = random(1,5); //should be the same each time
}
}

The code from JohnG I can't handle. Do I need a extra class "Random" to get this problem solved???


Re: Partial RandomSeed()
Reply #6 - Jan 23rd, 2008, 8:32pm
 
Your problem can be solved much easier:

Code:
float x;
float y;

void setup()
{
//normal setup
x=random(1.5);
y=random(1.5);
}

void draw()
{
//stuff
float a=random(0.1);
//stuff that uses x y and a
//more stuff...
}
Page Index Toggle Pages: 1