How would I set a variable to a random number?
How would I go about setting a variable to a number between -100 to 100. I have tried [var = (-100,100)] but it didn't work.
How would I go about setting a variable to a number between -100 to 100. I have tried [var = (-100,100)] but it didn't work.
Always worthwhile to dig through the documentation :)
https://github.com/pmgl/microstudio/wiki/en-microScript-cheatsheet#random
// random number in the rangle [0 .. 1] random.next()
// random integer in the range [0 .. 99] random.nextInt(100)
For your case, you need it as float or integer? Here 2 helper functions that give you the inclusive range:
// returns random number (float) within range
rndRange = function(lo,hi)
return random.next()*(hi-lo)+lo
end
// returns random number (integer) within range (inclusive)
rndRangeInt = function(lo,hi)
return random.nextInt(hi-lo+1)+lo
end
For integer you would call it like this:
var = rndRangeInt(-100,100)
Hope this helpsLive Long and Tinker
@TinkerSmith I did not know there was a github page