How to generate a real random number in C? -



How to generate a real random number in C? -

i trying generate random probability maximum of given probability. how generate random real value between 0 , 0.5 in c?

you cannot generate really random number in portable c99. utilize prng (and perhaps seed current time).

and computers don't know true real numbers. floating point. see http://floating-point-gui.de/

actually believe universe not know real numbers (think cardinality argument similar cantor's diagonal argument). inquire physicists or philosophers.

some operating systems or implementations have prngs, , systems (including) hardware have genuine random generators.

read random(3) & drand48(3) if scheme has it. if on linux, read random(4)

you might try

double my_random_number /* between 0 & 0.5 */ = drand48() * 0.5;

to generate uniformly distributed random number >= 0 , < 0.5

see c++11 standard header <random> if take code in c++ ...

c

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -