Im Confused

I am making a turn - based rpg game in which you fight monsters. i have a question though, Is there a function that can randomize ints without values? Or bool values? Say i created 10 different monters, could randomize them so that you fight a different 1 each time? (without rand) Or do you have to use rand?
What's wrong with rand()?
Nothing, I was just wondering if there was another way...
There are many ways, but if there's nothing wrong with rand() (there are reasons why someone wouldn't want to use rand(), by the way), you might as well use it.
Ok I'll Use It. My game will rock!
Maybe you were looking for this?:

1
2
3
4
5
6
#include <stdlib.h>
#include <time.h>

srand(time(NULL));

int myRandom = rand()%MAX;


Without srand(time(NULL)), you will always get the same random numbers in the same order. I hope this helps.
If you're using C++ please use the standard libraries, i.e. cstdlib and ctime. The corresponding functions are from the namespace std;.
Last edited on
...? Until C++0x there's no PRNG in the std namespace.
Topic archived. No new replies allowed.