Thread: C++ randomizing
View Single Post
  #2 (permalink)  
Old November 17th, 2006, 08:16 AM
Geo121 Geo121 is offline
Friend of Wrox
 
Join Date: Jan 2006
Posts: 103
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Geo121
Default

Please keep in mind that complete and truthful randomness is impossible to calculate
Instead when a number is artificially randomized then it becomes part of a large almost hidden pattern
But sooner or later the numbers will repeat themselves in the same pattern

This is the best random function I have ever designed
yet it is extremely flawed due to it's required positive values
but if you had a negative number that you wanted to include just find the RANGE (biggest number minus smallest number) and do a random for 0 to that and then subtract the deficate example below

int random(unsigned short int start, unsigned short int finish)
{
    srand((unsigned)time(0));
    int rint;
    rint = (rand()%(finish+1)) + start;
    return rint;
}

just enter in the start and finish numbers to get your random number
so random number 1 to 6 :

random(1, 6);

so random number -6 to 3 :

int randInt = random(0, 9);
randInt -= 6;

~ Geo

 ~ You are unique, just like everyone else
Reply With Quote