[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: urgent problem
On Thu, 21 Jan 1999, Chaim Zucker wrote:
> i know this is not quite the place to ask for this .... but
You're damn right ! This is certainly not the place for such a question.
You should have sent it to one of the C beginner's news groups, or at
least to the israeli linux programming mailing list.
> i have (in c++) a function that uses rand() (to print a matriza) i have to
> give the user the option to print it as many times as he likes but
> everytime the function is calles rand() comes upwith different numbers
> what can i do to keep the same numbers coming up?
You have two basic ways to do it. The first one is save the matrix in the
memory (as a type int[][] or int ** if you prefer).
If you don't want to use that technique, you can first initialize srand()
with the current time, then get a random number, and then use this number
as the initialization of srand() before you print the matrices to the
screen.
> i am using solaris/SunOs on sparc/hds/pc and using the function:
> rand() % 100
On many systems this won't produce a uniform random number . The
correct way to produce a random number in the range of 0 to n-1 is:
(double( rand())/RAND_MAX)*n.
Good luck, and please, don't post any more C++ related questions to the
list (especially that trivial questions)
Liran.
__________________________________________________________________________
Liran Zvibel. | " Never attribute to conspiracy
System Programmer, System Administrator. | what may be adequately
email : liranz@actcom.co.il | explained by stupidity
phone : 972 - 3 - 6493939 | or incompetence. "
home : http://www.math.tau.ac.il/~liranz|
UIN: 708004 ; WHOIS : LZ615 | -- Shallit's Razor
--------------------------------------------------------------------------