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 & HelpPrograms › random problems need help thx
Page Index Toggle Pages: 1
random problems need help thx (Read 583 times)
random problems need help thx
Apr 23rd, 2010, 7:45pm
 
how to make this int(random(0,5)) in the code onle randomly choose a number 1 time then stop. I tried to add noLoop() above it, but the followings also stopped loop, that is not what I want. so... please help me. thx, here is the code
PImage[] pstory = new PImage[30];
int j=0;
int s;
PImage k ;
void setup (){
 size (650,800);

for ( int i = 0; i< pstory.length; i++ )
{
pstory[i] = loadImage( i + ".jpg" );}  
}
void draw(){
 println ("j="+j);
if (j>=pstory.length){
 j=0;}else if (j>=3){
   s=int(random (0,5)); I need this one onle run once each time!
   println("s="+s);
   if (s==0){
     j=3;}
    if (s==1){
     j=5;}
      if (s==2){
     j=9;}
      if (s==3){
     j=15;}
      if (s==4){
     j=21;}
 }
 k = pstory [j];
background (k);
}

void mouseReleased(){
   j++;
}
Re: random problems need help thx
Reply #1 - Apr 24th, 2010, 3:48am
 
You need to clarify what you mean.
Do you only want the value of s set once each time the program is run?
Do you want it to change when j changes from 2 to 3?
Page Index Toggle Pages: 1