Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

-Darius-

Random number problem

This topic is 6924 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
anyone?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!