Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // XOR SHIFT 16 bit RNG (Modified version of George Marsaglia's xorshift)
- // http://www.arklyffe.com/main/2010/08/29/xorshift-pseudorandom-number-generator/
- //
- //
- /* 60 Values that work for A,B,C in the 16-bit XORShift RNG.
- (1, 1, 14) (1, 1, 15) (1, 5, 2 ) (1, 7, 4 ) (1, 7, 11) (1, 11, 3 )
- (1, 15, 6 ) (1, 15, 7 ) (2, 5, 1 ) (2, 5, 13) (2, 5, 15) (2, 7, 13)
- (2, 7, 15) (3, 1, 12) (3, 1, 15) (3, 5, 11) (3, 11, 1 ) (3, 11, 11)
- (3, 13, 9 ) (4, 3, 7 ) (4, 7, 1 ) (4, 11, 11) (5, 7, 14) (5, 9, 8 )
- (5, 11, 6 ) (5, 11, 11) (6, 7, 13) (6, 11, 5 ) (6, 15, 1 ) (7, 1, 11)
- (7, 3, 4 ) (7, 9, 8 ) (7, 9, 13) (7, 15, 1 ) (8, 9, 5 ) (8, 9, 7 )
- (9, 7, 13) (9, 13, 3 ) (11, 1, 7) (11, 3, 13) (11, 5, 3 ) (11, 7, 1 )
- (11,11, 3 ) (11,11, 4 ) (11,11, 5) (12, 1, 3 ) (12, 3, 13) (13, 3, 11)
- (13, 3, 12) (13, 5, 2 ) (13, 7, 2) (13, 7, 6 ) (13, 7, 9 ) (13, 9, 7 )
- (14, 1, 1 ) (14, 7, 5 ) (15, 1, 1) (15, 1, 3 ) (15, 5, 2 ) (15, 7, 2 )
- */
- int PR_Y = 1; //Seed, must not be zero.
- #define PR_A 13
- #define PR_B 9
- #define PR_C 7
- function int PRandom(int min, int max) //Dont use negative values with this function
- {
- int value;
- if(min == max) return min;
- if(max < min)
- { //Swap values
- value = max;
- max = min;
- min = value;
- }
- PR_Y ^= (PR_Y << PR_A);
- PR_Y ^= (PR_Y >> PR_B);
- PR_Y ^= (PR_Y << PR_C);
- value = PR_Y;
- if (value < 0) value = -value;
- value = value % (max - min + 1);
- value += min;
- return value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement