Random Number Generation

Hi all.

I believe that I've already asked about this subject before, but I had no idea what people posted means. Could you explain how it works and also how to generate random numbers between two set numbers (like 5 and 10) and how to generate a number between 0 and something else.

If it's ok, could you write a short explanation saying what I will need to edit if I want to make a random number function.

Thanks all.
Are you asking about how to implement rand() or how to use it?

First is explained in wikipedia
http://en.wikipedia.org/wiki/Random_number_generation
http://en.wikipedia.org/wiki/Linear_congruential_generator

Second I can try to explain if needed.
I found that a few minutes ago, but thanks. What I don't understand now is how can I get it to randomly generate a number without the time(null) stuff as the program I am making will need to random generate maps for the player to move around on.

I got all the output stuff sorted but when I run the program all the walls are hugged together in one place and so are the empty floors. Sometimes the player is even trapped between four walls.

I know that I could slow down the output process to make things better, but that will take a while when the computer has to randomly pick tiles for over 200 spaces. As well as that the computer will have to do this process once, pause for about 10 miliseconds, then do it again repeatedly. If I add even a small pause the engine will be slowed down a lot.
Last edited on
You're only supposed to srand() once. Also, simply rand()ing all tiles is not a great idea. The map will not be very interesting most of the time. You'll need a smarter algorithm if you want a map with rooms and corridors or etc.
I don't really care as this is going to be a function for later on in the game, not now. But thanks for the help anyway. Now I at least know some stuff about rand()
Topic archived. No new replies allowed.