Thông minh 
mình cũng tìm được sự phức tạp của ví dụ khác
Question
Sign in to vote
0
Sign in to vote
wjhwong wrote:
May I know how to generate 64 bit random number using rand()?
What’s the code?
Here is a simple polynomial-based random number generator that produces 32
bits at a time. You can call it twice and combine the values:
__int64 rand64() {
return ((__int64)(xorshift())<<32)|xorshift();
}
//...
static unsigned long
x=123456789,
y=362436069,
z=521288629,
w=88675123,
v=886756453;
/* replace defaults with five random seed values in calling program */
unsigned long xorshift(void)
{
unsigned long t = x^(x>>7);
x=y; y=z; z=w; w=v;
v=(v^(v<<6))^(t^(t<<13));
return (y+y+1)*v;
}
#include <stdio.h>
int
main()
{
int i;
for( i = 0; i < 25; i++ )
printf( "%08x\n", xorshift() );
}
–
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.
Tim Roberts, DDK MVP