Number Generator Code

Simple little algorithms to generate a random and a sequenced integer value every N seconds, between MIN and MAX values, starting when you begin an activity.

This example changes the value every 5 seconds, between the values of 5 and 10. I use this to sequentially or randomly select values within an array, between array elements [5] and [10]. So the value is the array index.

Static variables (at the global or module level). 

var ranValue, seqValue;
var delaySec = 5; // change value this frequently in seconds
var increMin = 5; // minimim value
var increMax = 10; // maximum value

And the code to generate the values - UPDATED to start at the MIN value until Activity Start

// generate a random value every N seconds, between MIN and MAX. Set to MIN before Activity Start
if (ranValue == null) { Math.srand(System.getTimer()); }
if (Times[:elapsed] == 0) { ranValue = increMin; }
else if ((Times[:elapsed]/1000)%(delaySec) == 0) { ranValue = Math.rand()%(increMax - increMin + 1) + increMin; }

// generate a sequential value every N seconds, between MIN and MAX. Set to MIN before Activity Start
seqValue = (Times[:elapsed]/(1000*delaySec))%(increMax - increMin + 1) + increMin;