Re: [AD] simple question on randomizing

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


this is what i do...

unsigned int my_rand(unsigned int range)
{
    unsigned int m = ( rand() << 15 ) | rand();
    return m % range;
}

it seems to give me nice randomness









sorry for such an easy question but the way I learned how to do random numbers is really not what I'm looking for...

/*

srand(static_cast<unsigned>(time(NULL)));
  int random_integer = (rand()% 1000);

*/


it only increases the number slightly until it reaches the max and then it starts over again.. is there a way to put some type of high and low spread on the numbers to make it really random? I understand it has something to do with the clock.. I tried using floats but that didnt really do any good either.





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/