Your program should only call srand() once! If you call it before every
all to rand(), then very bad things will happen. time() has a return
resolution of 1 second, so you may then only produce one random number /
second.
Byt, you don't et any true random numbers from srand() + rand(). The
sequence of calls from rand() is pseudo-random. Many calls to srand() may
not be used, since the rand() function isn't guaranteed to produce a
reasonable number distribution from multiple seeds.
Why do you need "pure random" numbers? I hope this hasn't anything to do
with cryptography. If it does, then you better stop now since cryptography
requires cryptographically strong random numbers - and if you know what
they are, you would not play along with srand() + rand :)
/pwm
On Mon, 26 Nov 2007, Andr=E9 Mac=E1rio Barros wrote:
> Dear Users,
>
> I=B4m working with srand/rand functions
> to generate random values.
>
> I have three functions that call rand()
> and these functions are defined inside a
> .cpp file that belongs to a project.
>
> The file with main(), that calls these
> three functions, is another file that also
> belongs to this project. The calls are made
> inside a fast loop.
>
> The first attempt to generate pure random
> numbers was using srand((unsigned) time(&t))
> at in the file with main(). t is a variable
> of type time_t. I got the same sequence of
> results, that is, rand() did behave as no
> previous srand() was called.
>
>
> The second attempt to generate pure random
> numbers was using srand((unsigned) time(&t))
> inside the three functions at the first time
> the functions were called. The results obtained
> presented the following behaviour:
> a) running directly: the same results;
> b) debuging step-by-step (with time intervals
> greater than 1 second): I got the expected
> results. I credit this to variable t, which
> could get different arguments.
>
> My question is:
> If my attempts were correct, in the point of view
> of achieve my goal, does anybody know how can I
> solve this? :-)))
>
> Regards
> Andre
>
>
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.5.503 / Virus Database: 269.16.7/1151 - Release Date: 25/11/20=
07
> 16:24
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|