MT or KISS ?
Moderators: hgm, Rebel, chrisw
-
- Posts: 411
- Joined: Thu Dec 30, 2010 4:48 am
Re: MT or KISS ?
your zobrist hash is already effectively a random value distributing things over all buckets. you can use modulus by number of buckets (does not need to be any special number), but you can also make your number of buckets 2^n. thus the modulus is the same as just the lowest n bits and you can get your bucket number with a simple bit-wise and.
-
- Posts: 3232
- Joined: Mon May 31, 2010 1:29 pm
- Full name: lucasart
Re: MT or KISS ?
So it's masochism, right ? That's what I thoughtDan Honeycutt wrote:I can't answer right now, got an appointment with my dominatrix in a little while.lucasart wrote:You seem to be quite a competent programmer. So why do you punish yourself with JavaDan Honeycutt wrote:I found a FORTRAN (which, like Java that I'm working in, uses signed integers)
Best
Dan H.
-
- Posts: 3232
- Joined: Mon May 31, 2010 1:29 pm
- Full name: lucasart
Re: MT or KISS ?
have a look there, there's all you need to know about LCGvoyagerOne wrote: Also... can I simply use modulus for the hash function? If so... what's a "good" modulus number to use? Should it be prime?
http://en.wikipedia.org/wiki/Linear_con ... _generator
-
- Posts: 690
- Joined: Mon Apr 19, 2010 7:07 pm
- Location: Sweden
- Full name: Peter Osterlund
Re: MT or KISS ?
I don't think SecureRandom is guaranteed to produce the same sequence for all java implementations, even if you seed it with the same value. This is a problem if you want the search to be identical across different platforms and java implementations.voyagerOne wrote:@ Peter:
What's the danger of simply using SecureRandom nextLong()?
-
- Posts: 454
- Joined: Sat Apr 04, 2009 6:44 pm
- Location: Bulgaria
Re: MT or KISS ?
This is the full code of mine:
Code: Select all
#include <stdio.h>
#ifndef true
#define true 1
#define false 0
#define bool int
#endif
typedef unsigned long long uint64;
typedef unsigned int uint32;
#define HDMIN 21//the required minimum hamming distance
#define HDMAX 40//the maximum hamming distance
#define HS 4096 //the history stack size
#define MS 10 //the count of separated groups of numbers
//int max_size[MS] = {1920, 16, 128, 2, 0, 0, 0, 0, 0, 0};//the divided sizes of the groups
int max_size[MS] = {1792, 15, 127, 1, 0, 0, 0, 0, 0, 0};
uint64 __inline rand64()
{//generates 64-bit rnd number
return ((uint64)rand()
^ ((uint64)rand() << 15)
^ ((uint64)rand() << 30)
^ ((uint64)rand() << 45)
^ ((uint64)rand() << 60));
}
bool __inline long_enough(uint64 rn)
{//checks if the number has a 16 digits and not less
int x;
char strbuff[24] = {0};
sprintf(&strbuff[0], "%#llx", rn);
x = strlen(strbuff);
if (x < 18) return false;
return true;
}
uint32 __inline hamdist(uint64 x, uint64 y)
{//returning the hamming distance between the 2 bitstrings:
uint32 dist = 0;
uint64 val = x ^ y;
while(val)
{ ++dist;
val &= val - 1;
}
return dist;
}
int main()
{
int i,j,k; //loop counters;
FILE *f; //the 'numbers.txt' file descriptor
int tab = 0; //'4 on a line' counter
uint64 rnd_number; //the current rnd number
uint64 history_stack[HS] = {0};//stack of generated numbers, the 1s element is independent - 'to compare with'
int hs_pos = 1; //current position in the history stack
bool num_ok = false;
int hd = 0;//hamming distance returned value
uint32 num_count = 0;
uint32 total_num_count = 0;
//calculating the total
for(i = 0; i < MS; i++)
total_num_count += max_size[i];
printf("total: %d\n",total_num_count);
printf("current:\n");
//setting the first element (separately from the rest)
do{rnd_number = rand64();
}while(!long_enough(rnd_number));
history_stack[0] = rnd_number;
//start:
f = fopen("numbers.txt", "w");
for(i = 0; i < MS; i++)
{
for(j = 0; j < max_size[i];j++)
{ do
{ num_ok = true;
//checking the lenght after generate:
do{rnd_number = rand64();
}while(!long_enough(rnd_number));
//checking the hd with the rest numbers in stack:
for(k = 0; k < hs_pos; k++){
//check if the number exists (duplicate)
if(rnd_number == history_stack[k])
{ num_ok = false;
break;
}
hd = hamdist(rnd_number, history_stack[k]);
if((hd < HDMIN) || (hd > HDMAX))
{ num_ok = false;
break;
}
}
}while(!num_ok);
//the number is ok now, so increase the position in stack and record it:
history_stack[++hs_pos] = rnd_number;
//saving:
tab++;
fprintf(f, "\t%#llx", rnd_number);
fprintf(f, "%s", "ULL");
if((j + 1) != max_size[i]) fprintf(f,"%s",",");
//the line of 4 is ended ?:
if(tab == 4) {
fprintf(f, "%s", "\n");
tab = 0;
}
//printing out the recorded count so far:
num_count++;
printf("\r%d",num_count);
}
//separating the portions in file:
fprintf(f, "%s", "\n\n\n\n");
}//exit:
fclose(f);
printf("\n\n");
system("pause");
return 0;
}
-
- Posts: 931
- Joined: Tue Mar 09, 2010 3:46 pm
- Location: New York
- Full name: Álvaro Begué (RuyDos)
Re: MT or KISS ?
Chances are any method is good enough for your purpose. But if you want to get really good random numbers and you are using Linux, read the numbers you need from /dev/random and build a hard-coded table with them. It might take a while of moving the mouse around and typing garbage for it to gather enough entropy, but the results are likely to be very good random numbers.