Let's see. This is a method of getting a random value in the interval between
min
and
max
:
function randomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; }
The numbers will have statistically uniform distribution withing the said interval.
Now, if you have a set of some objects, representing, say, a group, you can put them on an array
var objects = [object1, object2, ...]
; it does not matter what they are. You can choose one of these objects using the array element syntax,
[someIndex]
. If your generate a random value for
someIndex
, you will get an object randomly chosen from this set. Using this idea, you can solve your problem.
—SA