Jump to content
  • Advertisement

Archived

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

Popper_Demi

generating random numbers in c++

This topic is 6918 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

how would i go about generating a random number in c++? for example, how would i generate a number that would be in the range of 1 and 12? Thanx in advance ~Popper_Demi

Share this post


Link to post
Share on other sites
Advertisement
One other thing you need to know: rand() is not truely
random. It gives the same sequence of numbers for a given "seed". You can set the seed with srand(int seed). This fact is good for debugging; it''s nice to see aliens appear in the same order to track down bugs, however, you generally want to base the seed on something that changes each time you run the program: The current time, process/thread ID, etc.

-- Pryankster

Share this post


Link to post
Share on other sites
Here's an example code for changing seeds:
#include time.h
srand(time( NULL ) );
call the rand() fuction.


Edited by - Iceman on May 15, 2000 8:57:27 AM

Edited by - Iceman on May 15, 2000 8:57:55 AM

Share this post


Link to post
Share on other sites
Theres a flaming post about this over at the OpenGL Beginner''s forum

http://www.opengl.org

the link to the forum is in the right column

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!