Random number

Feb 21, 2006 1 Replies

Hi frnds i need ur help.plz tell me by what seed values to be used to generate 1000 random nos using linear congruential method.(using c programing)


Wow are you in the wrong newgroup!

The following code was written in Visual C++ 6.0, but should compile fine on most computers (given u have a compiler, which if your reading this I assume you do). The program outputs three random values... /*Program displays three random integers.

*/ /* Header: iostream Reason: Input/Output stream Header: cstdlib Reason: For functions rand and srand Header: time.h Reason: For function time, and for data type time_t */ #include <iostream>

#include <cstdlib>

#include <time.h>

int main() { /* Declare variable to hold seconds on clock.

*/ time_t seconds; /* Get value from system clock and place in seconds variable. */ time(&seconds); /* Convert seconds to a unsigned integer. */ srand((unsigned int) seconds); /* Output random values. */ cout<< rand() << endl; cout<< rand() << endl; cout<< rand() << endl; return 0; }

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required