Possible duplicate:What is the correct way to use the rand () function in C ++?
When I run the program below, I always get the same values every time. Is rand not a real random function?
int main() { while(1) { getch(); cout<<rand()<<endl; } }
In each run, I get the values below.
41
18467
6334
26500
19169
15724
......
. rand() - , . "" , rand(), . -, "" (, ), . , , - .
, seed
? , , :)
, , , "" . , , , . tic- . .
Microsoft, rand_s, ( , ): http://msdn.microsoft.com/en-us/library/sxtz2fa8%28VS.80%29.aspx
/dev/urandom Linux CryptGenRandom() Windows, .
/dev/urandom
CryptGenRandom()
srand() .
, "" . , , , - , 2 ^ 48.
, :
long randomLong(unsigned int x) { x ^= (x << 21); // x is a non zero seed value x ^= (x >> 35); x ^= (x << 4); return x; }
This is taken from the following article: http://www.jstatsoft.org/v08/i14/paper
What a really interesting article describing some low-cost random number generators
Source: https://habr.com/ru/post/1746873/More articles:Best practice for creating an auxiliary method of a business object - memory-managementDifference between document classes - javaWhat is the reason for choosing the current syntax `import foo.bar. {Baz => _} `to exclude something from import? - importAssert.AreEqual () exception in VS2010 - .netTruncating a base table in a view - sql-server-2008best approach to validating jsf form - jsfProper use of s / rand or Boost :: random - c ++Download ASP.Net file with empty file assembly - jqueryкак смоделировать поток последователей в appengine? - pythonA good way to implement a tweeter-like tracking device system? - google-app-engineAll Articles