-
Notifications
You must be signed in to change notification settings - Fork 0
/
uber_rand.c
63 lines (61 loc) · 2.24 KB
/
uber_rand.c
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*!
* Set of functions to calculate the probabilty of n number of items adding up to s
* with sides x. The question that this program relates to can be found at the url of
* http://stackoverflow.com/questions/6394120/
*
* Copyright 2011, Macarthur Inbody
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the Lesser GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*
* 2011-06-20 06:03:57 PM -0400
*
* These functions work by any input that is provided. For a function demonstrating it.
* Please look at the second source file at the post of the question on stack overflow.
* It also includes an answer for implenting it using recursion if that is your favored
* way of doing it. I personally do not feel comfortable working with recursion so that is
* why I went with the implementation that I have included.
*/
static unsigned int initial_seeds[500];
static unsigned int main_seeds[4096];
void ur_gen_seeds(unsigned int total_seeds){
while(total_seeds>=0){
initial_seeds[0]=initial_seeds[1];
initial_seeds[1]=initial_seeds[2];
initial_seeds[2]=initial_seeds[3];
initial_seeds[3]=initial_seeds[4];
initial_seeds[4]=initial_seeds[5];
initial_seeds[5]=(initial_seeds[5]^(initial_seeds[5]<<6))^(initial_seeds[1]^(initial_seeds[1]<<13));
main_seeds[total_seeds]=(initial_seeds[1]+initial_seeds[2])*(initial_seeds[5]+initial_seeds[0]);
--total_seeds;
}
}
int unsigned mcwm4096(unsigned int c){
int i=4095;
char loops=5;
unsigned long long t, a=1872LL;
unsigned long x,r=0xfffffffe;
while(loops!=0){
i=(i+1)&4095;
t=a*main_seeds[i]+c;
c=(t>>32);
x=t+c;
if(x<c){
x++;
c++;
}
main_seeds[i]=r-x;
--loops;
}
return main_seeds[i];
}