However to keep it fast i didnt include a check if the user inputs a higher number as the lowest parameter. Just add this if you want, but i want it to be as fast as possible (i use it often).
Erik
Code: Select all
#include <ctime> // For time()
#include <cstdlib> // For srand() and rand()
Code: Select all
float getRandomF(float low,float high){
return low+rand()/(float)RAND_MAX*(high-low);
}
int getRandom(int low,int high){
return low + rand()%(high - low + 1);
}
Code: Select all
srand(time(0)); // Run once at startup tp randomize
//now get some random stuff!
int myInt=getRandom(5,9);
float myFloat=getRandomF(1.2,1.6);
