Reputation: 20774
What's the seed used by C's random()
if I don't initialize it with srandom()
?
Is it system time?
Upvotes: 0
Views: 90
Reputation: 4090
ISO C Random Number Functions You can check here that If you call rand before a seed has been established with srand, it uses the value 1 as a default seed.
http://www.gnu.org/software/libc/manual/html_node/ISO-Random.html
Upvotes: 0
Reputation: 6411
As another answer correctly states, random()
is not in ISO C. It is, however, in POSIX, where the rule is analogous to ISO C's rand()
:
Like
rand()
,random()
shall produce by default a sequence of numbers that can be duplicated by callingsrandom()
with 1 as the seed.
Upvotes: 2
Reputation: 13772
random()
is not in standard C.
ISO C defines rand()
and srand()
.
#include <stdlib.h>
int rand(void);
void srand(unsigned int seed);
The standard answers your question in section 7.22.2:
If
rand
is called before any calls tosrand
have been made, the same sequence shall be generated as whensrand
is first called with a seed value of 1.
Upvotes: 5