We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I'm new to processing. I was looking for solution half of a day before asking I would like to pick up random from an array. how the code would look like ?
int[] dice = {15,56,3,5,54,10};
void draw(){
if (mousePressed==true){
for(int i=0; i<=dice.length; i++){
//??
}
}
}
Answers
There are some issues with your code which you will discover.
The draw method is executed ~60 times a second so will you hold done a mouse button you could get several changes. It is better to use the mouse clicked event and catch this outside the draw method and store the selected random number in a variable so here it is
Extra tip: No need to use 2 arguments for random() when picking from 0:
value = dice[(int) random(dice.length)];
http://processing.org/reference/random_.html
Another option is the combo noLoop() + redraw():
http://processing.org/reference/noLoop_.html
http://processing.org/reference/redraw_.html
Thank you guys!