void cycles volatile unsigned __int64 rtn if defined _MSC_VER __asm сч

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
void cycles(volatile unsigned __int64 *rtn)
{
#if defined(_MSC_VER)
__asm // считываем Pentium Time Stamp Counter
{ cpuid
rdtsc
mov ecx,rtn
mov [ecx],eax
mov [ecx+4],edx
cpuid
}
#else
#include <time.h>
time_t tt;
tt = time(NULL);
((unsigned long*)rtn)[0] = tt;
((unsigned long*)rtn)[1] = tt & -36969l;
return;
#endif
}
#define rand(a,b) (((a = 36969 * (a & 65535) + (a >> 16)) << 16) + \
(b = 18000 * (b & 65535) + (b >> 16)))
void FillRand(unsigned char *key, const int len)
{
static unsigned long a[2], mt = 1, count = 4;
static char r[4];
int i;
if(mt) { mt = 0; cycles((unsigned __int64 *)a); }
for(i = 0; i < len; ++i)
{
if(count == 4)
{
*(unsigned long*)r = rand(a[0], a[1]);
count = 0;
}
key[i] = r[count++];
}
}