Welcome Guest [Log In] [Register]
Viewing Single Post From: Avalanche Test
loki
Advanced Member
[ *  *  * ]
Hey all, I found neat C# code that calcualtes avalanche, I have ported it to VB and it seems to work fine (well not really its vb). I have ported to c as well, with results that are not working. Here is the site, Hash avalanche

here is my port that doesn't work, I don't know can you see my error ???

Code:
 

#include <stdio.h>
#include <windows.h>

unsigned long state;

unsigned long rnd;

static void mix(void) {
state += (state << 12);
state ^= (state >> 22);
state += (state << 4);
state ^= (state >> 9);
state += (state << 10);
state ^= (state >> 2);
state += (state << 7);
state ^= (state >> 12);
}

static unsigned long random(unsigned long x) {
      rnd = (unsigned long)(0x19660D * x + 0x3C6EF35F);
      return rnd;
      }

void AvalancheMatrix(int trials, int repetitions) {
int size = 32;

unsigned long inb, outb, save, nlongs = 1;
unsigned long rng;
unsigned long t[size][size];
double results[size][size];
double dtrials = trials;
int r,i,j;

while(trials > 0) {
 rng = random(rnd);
 state = rng;
 save = state;

 for(r=0;r<repetitions;r++) {
  mix();
 }

 inb = state;

 for(i=0;i<size;i++) {
  state = save ^ (1U << i);

  for(r=0;r<repetitions;r++) {
   mix();
  }

  outb = state ^ inb;

  for(j=0;j<size;j++) {
   if(outb & 0x1 == 1) {
    t[i][j] = t[i][j] + 1;
   }

   outb >> 1;
  }
 }
trials = trials - 1;
}

for(i=0;i<size;i++) {
 for(j=0;j<size;j++) {
  results[i][j] = t[i][j] / dtrials;
 }
}

for(i=0;i<size;i++) {
       printf("%02d ", i);
 for(j=0;j<size;j++) {
    printf("%2d ", results[i][j] * 100);
 }
 printf("\n");
}
}

int main (void) {
   rnd = (GetCurrentThreadId() + GetTickCount());
   
AvalancheMatrix(1000, 1);

   return 0;
}


If any one can figure this out in c that would be great.
c(x) = 3x3 + x2 + x + 2; Find the inverse
Offline Profile Quote Post
Avalanche Test · Off-topic