Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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).

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

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?

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; // secondstime_t seed;
seed = time(NULL) + offset; // current GMT
srand( seed );

![]() |
![]() |
![]() |

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