Unifying random generated data across different Python versions
()
| 191 | pass |
| 192 | |
| 193 | def unisonRandom(): |
| 194 | """ |
| 195 | Unifying random generated data across different Python versions |
| 196 | """ |
| 197 | |
| 198 | def _lcg(): |
| 199 | global _rand |
| 200 | a = 1140671485 |
| 201 | c = 128201163 |
| 202 | m = 2 ** 24 |
| 203 | _rand = (a * _rand + c) % m |
| 204 | return _rand |
| 205 | |
| 206 | def _randint(a, b): |
| 207 | _ = a + (_lcg() % (b - a + 1)) |
| 208 | return _ |
| 209 | |
| 210 | def _choice(seq): |
| 211 | return seq[_randint(0, len(seq) - 1)] |
| 212 | |
| 213 | def _sample(population, k): |
| 214 | return [_choice(population) for _ in xrange(k)] |
| 215 | |
| 216 | def _seed(seed): |
| 217 | global _rand |
| 218 | _rand = seed |
| 219 | |
| 220 | random.choice = _choice |
| 221 | random.randint = _randint |
| 222 | random.sample = _sample |
| 223 | random.seed = _seed |