🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Random number problem

Started by
1 comment, last by -Darius- 24 years, 1 month ago
I am having a problem with random numbers, in my program it is suppose to display 20 trees with random heights and random x,z coordinates. I have something like this. height=rand()%4; xcoord=rand()%30; zcoord=rand()%30; instead of giving me one number and displaying a tree with one random height and one xcoord,zcoord it will give me every single value from 0 to RAND_MAX. So each time my foorloop runs it will give me four trees with hieght values 0,1,2,3 and not just one number, also it gives me xcoords and zcoords from 0-30 and not a single number. So how do I get it to just give me one number and not every value from 0 to RAND_MAX?
Advertisement
anyone?
Im not sure what you are asking for...

You are complaining that you always get the same sequence of numbers ???

The rand() function will always give the same sequence of numbers, unless you seed first.

include the time.h

srand( (unsigned)time( NULL ) );



Edited by - Claus Hansen Ries on May 11, 2000 2:18:02 AM
Ries

This topic is closed to new replies.

Advertisement