Search the web
Sign In
New User? Sign Up
beginnersroguelikedevelopment · Beginners Roguelike Development - A place for discussing game development issues
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
need help with a RNG   Message List  
Reply | Forward Message #200 of 567 |
Re: need help with a RNG

Unfortunately, that method only works if you need a number between 0
and n. I have a somewhat strange but effective method for generating
random numbers (you specify the upper and lower bounds). It's in an
include file that I've created with several nice functions (let me
know if you want the whole file)

#include <windows.h> //for console functions
#include <stdlib.h> //the standard library
#include <time.h> //for time(NULL)

using namespace std; //the standard namespace
int seed = 1; //helps in randomizing

int Randint(int low, int high)
{
//c++ works so fast that it's tricky to get random numbers, even
if the seed is based on the computer clock
seed += ((time(NULL) + seed) % GetTickCount()); //tries to
randomize even further
srand(GetTickCount() + seed); //seed the
random generator
return (int)((rand() % (high - low + 1)) + low); //returns an
integer based on a randomly generated number
}

>
> number=rand()%6+1; //dice(1-6)





Thu Sep 15, 2005 12:42 am

gamer_2k4
Offline Offline
Send Email Send Email

Forward
Message #200 of 567 |
Expand Messages Author Sort by Date

Hi im kinda getting back into the c++ scene after about a 3 year period away from it and would appreciate some input on how to as easily as possible impliment...
Reece
omf_omf
Online Now Send Email
Sep 14, 2005
3:08 pm

... number=rand()%6+1; //dice(1-6)...
puma_htp
Offline Send Email
Sep 14, 2005
8:30 pm

Unfortunately, that method only works if you need a number between 0 and n. I have a somewhat strange but effective method for generating random numbers (you...
gamer_2k4
Offline Send Email
Sep 15, 2005
12:43 am

I think you'd be better off just call srand() occasionally (or just once when your code starts). I tend to just call "srand(time(NULL))" near my program entry...
allan175uk
Offline Send Email
Oct 1, 2005
10:12 pm

I use the random number generator for map creation, so if I want a 1 in 3 chance that a tree will be generated on a tile (instead of just grass) and I have a...
gamer_2k4
Offline Send Email
Oct 4, 2005
2:13 am

You'll still get a 1-in-3 chance of getting a tree just by using rand(). There are obviously better random number generators around which you could use, ones...
allan
allan175uk
Offline Send Email
Oct 4, 2005
8:08 am

... 1 ... just ... If your concern is the speed of the RNG you could always process your data in chunks (pseudocode follows): int x; char map[64][100]; while...
David
fthnature
Offline Send Email
Oct 4, 2005
8:36 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help