2 rand(), , , srand().
2-
1) - .
2) , .
1A # 1 time(), , .
1B , , - " - 12345, , , ".
1C , (@Will). , .
2A , , rand(), srand(). .
[Edit] Unix .
/dev/random /dev/urandom (@Dietrich Epp) .
2B ,
printf("Press enter\n");
unsigned u = 0;
while (!keyboard_hit()) u++;
srand(u);
. ( ^) , pid(), time(), react_time() .. (. @nodakai)
2 - : 1 20 ^ 10 (10 240 000 000 000) OP. , , .
, 2 - , . , - , , , , , , .
// pseudo code
n = 1;
repeat {
srand(time()^n^pid());
n++;
generate_random_number_sequence();
attempt exclusive r/w access to shared file.
if (file opened) {
read file;
if (different sequence) {
write new sequence and fclose()
if (no I/O errors) {
we are done - exit
}
}
fclose()
}
maybe sleep for a fraction of a second
maybe quit if repeated too often
}