In my code below, an object from my array is taken randomly. What I want however that there is always a defined ratio of how the objects are taken.
The ratio here is 1 ANIMAL, 1 LETTER, 4 INTEGERs, and I run the random selection in an interval 24 times and want the ratio to remain exactly the same: 4 ANIMALs, 4 LETTERs, 16 INTEGERs. As it is now, it will not do so and probably only approximate the true ratio for an infinite number of 'runs'.
var teststim = [
{stim: "CAT", type: "ANIMAL"},
{stim: "A", type: "LETTER"},
{stim: "3", type: "INTEGER"},
{stim: "7", type: "INTEGER"},
{stim: "5", type: "INTEGER"},
{stim: "9", type: "INTEGER"}]
newthing = teststim[Math.floor((Math.random() * teststim.length))];
How would I do that, is there a way to define the exact ratio of such a semi-random randomisation?