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 › random(int,int) not producing random
Page Index Toggle Pages: 1
random(int,int) not producing random? (Read 358 times)
random(int,int) not producing random?
Aug 20th, 2006, 10:18am
 
did i miss something?


void setup() {
}

void draw() {
 for(int i=0; i<100; i++) {
   float r = random(50, -50);
   println ("r " + r);
   stroke(r*5);
   line(50, i, 50+r, i);
 }
}

this code doesn't produce a random number for me.  it writes 50.   this is v 115, on windows.
Re: random(int,int) not producing random?
Reply #1 - Aug 20th, 2006, 11:06am
 
the left value must be smaller than the right for this method to work.

i think this fact is worth stating in the reference or even better, the method can be changed to find the smallest value itself.

Code:

float myLow = min(value1, value2);
float myHigh = max(value1, value2);

Re: random(int,int) not producing random?
Reply #2 - Aug 20th, 2006, 11:16pm
 
silly me, i knew i was missing something since i saw no other reports/bugs.  thanks.
Page Index Toggle Pages: 1