Computing.Net > Forums > Programming > Random Number Gen. In C

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Random Number Gen. In C

Reply to Message Icon

Name: brds
Date: February 19, 2005 at 16:59:01 Pacific
OS: xp
CPU/Ram: 512
Comment:

Hello,
I need to create a randome number generator for the number 1 through 52.... including 1 and 52. My teacher told me something about using GMT to create the random number, but i wasn't exactly sure what she meant. I need to make sure that the Generator is in strictly C (no C++ at all!) Can anybody please help?

Thanks,
Brds



Sponsored Link
Ads by Google

Response Number 1
Name: wizard-fred
Date: February 20, 2005 at 01:24:29 Pacific
Reply:

The most common reference to GMT is Greenwich Mean Time. One common method of seeding the random number generator is to use time (since it is highly unlikely that the program would be started at exactly the same time).


0

Response Number 2
Name: Mechanix2Go
Date: February 20, 2005 at 05:04:26 Pacific
Reply:

Hi wizaed,

Right that the prog would not likely be run at the same time each time.

But why mess with GMT?

You can use system time.

For added insurance, use system date & time.

M2


0

Response Number 3
Name: brds
Date: February 20, 2005 at 12:06:43 Pacific
Reply:

Right, i know that it refers to time, but i don't know how to code that... can anybody help me out with the coding?


0

Response Number 4
Name: egkenny
Date: February 20, 2005 at 20:01:35 Pacific
Reply:

Did your teacher mean for you to use the time function for seeding the random numbers.

The time function returns the number of seconds elapsed since midnight (00:00:00), January 1, 1970, Coordinated Universal Time, according to the system clock. The return value is stored in the location given by timer. This parameter may be NULL, in which case the return value is not stored.

For all practical purposes Coordinated Universal Time, aka UT and GMT are the same thing.

Example:

time_t seed;
seed = time(NULL);
srand( seed );

Note:

Depending upon the system the return value for the time function may give local time. To get GMT add 3600*time_zone, where time_zone is time zone number (west is positive and east is minus).

For US Eastern Standard Time offset
offset = 3600*5; // seconds

time_t seed;
seed = time(NULL) + offset; // current GMT
srand( seed );


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Random Number Gen. In C

Random Number Generator in C www.computing.net/answers/programming/random-number-generator-in-c/9566.html

Random number generator www.computing.net/answers/programming/random-number-generator/12990.html

Randomizing numbers www.computing.net/answers/programming/randomizing-numbers/141.html