FAQ
 
 
Cover  \ Exhibition  \ Learning  \ Reference  \ Download  \ Discourse   
      Language \ Environment \ Libraries \ Comparison
 
   
   
Abridged (A-Z) \ Complete (A-Z)  
   
  Reference for Processing (BETA) version 91+. If you have a previous version, use the reference included with your software. If you see any errors or have any comments, let us know.  
Name  

random()

   
Examples  
for(int i=0; i<100; i++) { 
  float r = random(50); 
  stroke(r*5); 
  line(50, i, 50+r, i); 
} 


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

Description   Generates random numbers. Each time the random() function is called, it returns an unexpected value within the specified range. If one parameter is passed to the function it will return a float between zero and the value of the parameter. The function call random(5) returns values between 0 and 5. If two parameters are passed, it will return a float with a value between the the parameters. The function call random(-5, 10.2) returns values between -5 and 10.2. To convert a floating-point random number to an integer, use the int() function.
   
Syntax  
random(value1);
random(value1, value2);
   
Parameters  
value1   int or float

value2   int or float

   
Returns   float
   
Usage   Web & Application
   
Related   noise()
 
 






   
 
Updated: Fri Jul 15 16:36:03 PDT 2005
 
 








Creative Commons License
 
  Processing is an open project initiated by Ben Fry and Casey Reas  
  © Info