|
Author |
Topic: Random element from an array? (Read 533 times) |
|
Phiil
|
Random element from an array?
« on: Feb 23rd, 2005, 4:48am » |
|
Hi folks, Quite simply, how do you go about extracting a random element from an array? I've set up an array, int [] majorscale = {0,2,4,5,7,9,11,12}; and I'd like to be able to have an event which acts using mouseY plus a random value from the array majorscale. My guess for the syntax was: midiOut.setNoteOn(9,mouseY+random(majorscale),mouseX); but I get this error message: "Semantic Error: No applicable overload for the method named "random" was found in type "BApplet". Perhaps you wanted the overloaded version "float random(float $1);" instead?" I'm putting this here as I'm pretty sure this is likely to be a basic syntactical error.... As you might have gathered, I'm playing around with the ProMIDI libraries. Thanks, Phil
|
|
|
|
eskimoblood
|
Re: Random element from an array?
« Reply #1 on: Feb 23rd, 2005, 10:14am » |
|
Try this: Code: int [] majorscale = {0,2,4,5,7,9,11,12}; int mj=int(random(majorscale.length)); midiOut.setNoteOn(9,mouseY+majorscale[mj],mouseX); |
|
|
|
|
|
Phiil
|
Re: Random element from an array?
« Reply #2 on: Feb 23rd, 2005, 1:47pm » |
|
Thank you Eskimoblood I'll give that a try when I've finished my current experiment (I've just got the video libraries working - quite fun). Phil
|
|
|
|
|