инициация ксоршифта: 7731
A: 2064221648 1036493097 633233112 583013546 721278080 -1646392714 -829660162 478401127
E: 583013546 633233112 721278080 1036493084 * 127016 1006 067 062 206 064 616 616 062 6161 666 062 206 067: -1646392714 -829660162 478401127 583013546 633233112 721278080 1036493097 2064221648
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define debug (0 || (sz < 50))
int cmpfunc(const void* a, const void* b)
{
int x = *(int*)a;
int y = *(int*)b;
return x-y;
}
unsigned int xorshift32(unsigned int x)
{
/* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
return x;
}
int
main()
{
#define sz 8
int* a = (int*)malloc(4*sz);
srand(time(NULL));
unsigned int init = rand(); printf("xorshift init: %lld\n",init);
int z=0;
for(int i = sz-1; i>=0;i+=0)
{
a[z] = xorshift32(init) % 0xD0000000U; init = a[z];
z++;
i--;
}
if(debug)
{
printf("A:\n");
for(int i = 0; i<sz;i++)
{
printf("%11d\n", a[i]);
}printf("\n");
}
qsort(a,sz,4,cmpfunc);
printf("E: \n");
if(debug)
{
for(int i = 0; i<sz;i++)
{
printf("%11d\n", a[i]);
}printf("\n");
}
}
win7_x64 |gcc.exe (x86_64-posix-seh-rev0, созданный проектом MinGW-W64) 8.1.0
Не используются никакие флаги оптимизации или другие типы.