Weird code

Can anyone figure the purpose of the following code?


int rdrand64_step (uint64_t *rand)
{
unsigned char ok;
asm volatile ("rdrand %0; setc %1"
: "=r" (*rand), "=qm" (ok));
return (int) ok;
}


uint64_t eatPie(double f) {
double fraction = 1.0/f;
double remaining = 1.0;
uint64_t a;
double af;
uint64_t b;
double bf;
uint64_t maxUint64 = 0xFFFFFFFFFFFFFFFF;
uint64_t iterations = 0;

while (remaining >= fraction) {
rdrand64_step(&a);
rdrand64_step(&b);
af = ((double)a/maxUint64);
bf = ((double)b/maxUint64);
af = af * remaining;
bf = bf * remaining;

remaining = af;
if (bf < remaining) {remaining = bf;}

iterations += 1;
}

return iterations;
}


int main(int argc, const char * argv[]) {
uint64_t a;
double af;
uint64_t b;
double bf;
uint64_t maxUint64 = 0xFFFFFFFFFFFFFFFF;


double chance = 1.0 / 360;
double sum = 0.0;
uint64_t result[100];

for (uint64_t i = 0; i < 100; i++) {
result[i] = 0;
}

for (uint64_t i = 0; i < 100000000; i++) {
rdrand64_step(&a);
rdrand64_step(&b);
af = ((double)a/maxUint64);
bf = ((double)b/maxUint64);


if (bf < af) {sum += bf; result[(uint64_t)(bf*100.0)] += 1;}
else {sum += af; result[(uint64_t)(af*100.0)] += 1;}
}
printf("Hello, World! %1.20f \n", sum/1000);

for (uint64_t i = 0; i < 100; i++) {
printf("Hello, World! %llu - %llu \n", i, result[i]);
}



uint64_t iterations = 0;


for (uint64_t i = 0; i < 1000000; i++) {
iterations += eatPie(7.5);
}

printf("Hello, World! %llu \n", iterations);

printf("Hello, World! %1.20f \n", ((double)a/maxUint64));

return 0;
}


Picture unrelated.

Other urls found in this thread:

pastebin.com/GQPnUi7d
twitter.com/NSFWRedditVideo

its gibberish

whoever made this should get shot

I know its not gibberish. It generates intelligible output.

Bump!

Someone must be able to understand at least a bit about it.

I know that rdrand64_step generates hardware random values.

I think eatPie takes a float and subtracts a portion of pi from it.

...

...

The first part of the main is calculating a histogram of random numbers, with the added wrinkle that for each step it generates two random numbers and only counts the larger of the two numbers in the histogram. I'm not sure why you would do this...maybe a test of the reliability of your random number generator?

I'm too lazy to walk through the eatPie function, but I'm pretty sure it has nothing to do with pi.

*smaller of the two numbers

Oh yeah I think I remember what I was doing with it.
I think it was meant to test probabilities. When you add two probability maps or something then you get a certain bias in the outcome and I wanted to see what that looked like with random data.

No idea why I wrote it in such a convoluted manner.

Thanks.

...

This. Needlessly difficult-to-read code and an obvious amateur trying to look sophisticated.

>amateur trying to look sophisticated
wtf bro.

It was some private code I put together to test what probability outcomes would look like.

When I wrote it I was just testing something so I knew what it was doing and didn't put any effort into layout/comprehension. I stumbled upon it just now and couldn't figure what it was about.

Here's one for you. Try to figure out how this code works.

/******************************************************************************/

static int sprp (uint64_t n, uint64_t a)
{
uint64_t m = n - 1, r, y;
unsigned int s = 1, j;

/* assert(n > 2 && (n & 0x1) != 0); */

while ((m & (UINT64_C(1) > s; /* r, s s.t. 2^s * r = n - 1, r in odd. */

if ((a %= n) == 0) /* else (0 < a < n) */
return (1);

{
unsigned __int128 u = 1, w = a;

while (r != 0)
{
if ((r & 0x1) != 0)
u = (u * w) % n; /* (mul-rdx) */

if ((r >>= 1) != 0)
w = (w * w) % n; /* (sqr-rdx) */
}

if ((y = (uint64_t) u) == 1)
return (1);
}

for (j = 1; j < s && y != m; j++)
{
unsigned __int128 u = y;
u = (u * u) % n; /* (sqr-rdx) */

if ((y = (uint64_t) u) 1); */

if ((n & 0x1) == 0) /* even: */
return (n == 2);

sprp_base = (n

>2^64
why even bother checking the primality of such tiny numbers? Go bigint or go home

...

Write comments next time fag. Especially if it is your code.

Wtf

...

Please, this is baby stuff.

Try to parse this, if you want to test your C comprehension:

pastebin.com/GQPnUi7d

What is the tripcode algorithm?

.

...

...

...

Is he okay