… | |
… | |
37 | #include <funcpoint.h> |
37 | #include <funcpoint.h> |
38 | #include <material.h> |
38 | #include <material.h> |
39 | |
39 | |
40 | #include <glib.h> |
40 | #include <glib.h> |
41 | |
41 | |
42 | rand_gen rndm (time (0)); |
42 | rand_gen rndm; |
43 | |
43 | |
|
|
44 | void |
44 | tausworthe_random_generator::tausworthe_random_generator (uint32_t seed) |
45 | tausworthe_random_generator::seed (uint32_t seed) |
45 | { |
46 | { |
46 | state [0] = max ( 2, seed * 69069U); |
47 | state [0] = max ( 2, seed * 69069U); |
47 | state [1] = max ( 8, state [0] * 69069U); |
48 | state [1] = max ( 8, state [0] * 69069U); |
48 | state [2] = max ( 16, state [1] * 69069U); |
49 | state [2] = max ( 16, state [1] * 69069U); |
49 | state [3] = max (128, state [2] * 69069U); |
50 | state [3] = max (128, state [2] * 69069U); |
… | |
… | |
59 | state [1] = ((state [1] & 0xFFFFFFF8U) << 2U) ^ (((state [1] << 2U) ^ state [1]) >> 27U); |
60 | state [1] = ((state [1] & 0xFFFFFFF8U) << 2U) ^ (((state [1] << 2U) ^ state [1]) >> 27U); |
60 | state [2] = ((state [2] & 0xFFFFFFF0U) << 7U) ^ (((state [2] << 13U) ^ state [2]) >> 21U); |
61 | state [2] = ((state [2] & 0xFFFFFFF0U) << 7U) ^ (((state [2] << 13U) ^ state [2]) >> 21U); |
61 | state [3] = ((state [3] & 0xFFFFFF80U) << 13U) ^ (((state [3] << 3U) ^ state [3]) >> 12U); |
62 | state [3] = ((state [3] & 0xFFFFFF80U) << 13U) ^ (((state [3] << 3U) ^ state [3]) >> 12U); |
62 | |
63 | |
63 | return state [0] ^ state [1] ^ state [2] ^ state [3]; |
64 | return state [0] ^ state [1] ^ state [2] ^ state [3]; |
|
|
65 | } |
|
|
66 | |
|
|
67 | uint32_t |
|
|
68 | tausworthe_random_generator::get_range (uint32_t r_max) |
|
|
69 | { |
|
|
70 | return next () % r_max; |
|
|
71 | } |
|
|
72 | |
|
|
73 | // return a number within (min .. max) |
|
|
74 | int |
|
|
75 | tausworthe_random_generator::get_range (int r_min, int r_max) |
|
|
76 | { |
|
|
77 | return r_min + (*this) (max (r_max - r_min + 1, 1)); |
64 | } |
78 | } |
65 | |
79 | |
66 | /* |
80 | /* |
67 | * The random functions here take luck into account when rolling random |
81 | * The random functions here take luck into account when rolling random |
68 | * dice or numbers. This function has less of an impact the larger the |
82 | * dice or numbers. This function has less of an impact the larger the |