PDA

Click to See Complete Forum and Search --> : c c++


Robert Briggs
Nov 6th, 2000, 11:55 AM
I am studying for a vb degree and I am at present learning 'c'.
I have a question to answer which is to build a pgm that prints out the number of people in a bus queue using the rand function there must never be no people in the queue
and a person departs or arrives every 30 seconds It is the rand function that is a problem to me, where do I put rand within the c program.

Hope someone can help

parksie
Nov 6th, 2000, 12:35 PM
rand() returns a random double between 0 and 1, so try something like:

long ulNumPeople = (long)((rand() * 50) + 1);

...which gives a maximum of 51 people, and a minimum of 1.

HarryW
Nov 6th, 2000, 06:23 PM
Which is the random function that returns an integer then? I'm sure I've seen code that's something like (rand % 50) + 1