Created
February 5, 2024 00:13
-
-
Save maierfelix/d25d674b8129a4cb39f734a9b25b2c39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdint.h> | |
| uint32_t TRIPLEInit1(uint32_t x) { | |
| x ^= x >> 16; | |
| x *= 0x7feb352dU; | |
| x ^= x >> 15; | |
| x *= 0x846ca68bU; | |
| x ^= x >> 16; | |
| return x; | |
| } | |
| uint32_t TRIPLEInit2(uint32_t x) { | |
| x ^= x >> 17; | |
| x *= 0xed5ad4bbU; | |
| x ^= x >> 11; | |
| x *= 0xac4c1b51U; | |
| x ^= x >> 15; | |
| x *= 0x31848babU; | |
| x ^= x >> 14; | |
| return x; | |
| } | |
| uint32_t TRIPLENext(uint32_t seed) { | |
| return (1664525u * seed + 1013904223u); | |
| } | |
| float TRIPLERandF01(uint32_t seed) { | |
| return (float)(seed) / (float)(0xffffffffU); | |
| } | |
| int main() | |
| { | |
| uint32_t x = 870146340u; | |
| uint32_t y = 3791971934u; | |
| uint32_t seed = TRIPLEInit1(x + TRIPLEInit1(y)); | |
| seed = TRIPLENext(seed); | |
| seed = TRIPLENext(seed); | |
| seed = TRIPLENext(seed); | |
| seed = TRIPLENext(seed); | |
| float random = TRIPLERandF01(seed); | |
| printf("Seed: %lu \n", (unsigned long)seed); | |
| printf("Random: %f \n", random); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function TRIPLEInit1(x) { | |
| x = BigInt.asUintN(32, x); | |
| x ^= x >> 16n; | |
| x *= 0x7feb352dn; | |
| x = BigInt.asUintN(32, x); | |
| x ^= x >> 15n; | |
| x *= 0x846ca68bn; | |
| x = BigInt.asUintN(32, x); | |
| x ^= x >> 16n; | |
| return x; | |
| } | |
| function TRIPLEInit2(x) { | |
| x = BigInt.asUintN(32, x); | |
| x ^= x >> 17n; | |
| x *= 0xed5ad4bbn; | |
| x = BigInt.asUintN(32, x); | |
| x ^= x >> 11n; | |
| x *= 0xac4c1b51n; | |
| x = BigInt.asUintN(32, x); | |
| x ^= x >> 15n; | |
| x *= 0x31848babn; | |
| x = BigInt.asUintN(32, x); | |
| x ^= x >> 14n; | |
| return x; | |
| } | |
| function TRIPLENext(seed) { | |
| return BigInt.asUintN(32, 1664525n * seed + 1013904223n); | |
| } | |
| function TRIPLERandF01(seed) { | |
| return Number(BigInt.asUintN(32, seed)) / (0xffffffff); | |
| } | |
| function main() { | |
| let x = 870146340n; | |
| let y = 3791971934n; | |
| let seed = TRIPLEInit1(x + TRIPLEInit1(y)); | |
| seed = TRIPLENext(seed); | |
| seed = TRIPLENext(seed); | |
| seed = TRIPLENext(seed); | |
| seed = TRIPLENext(seed); | |
| let random = TRIPLERandF01(seed); | |
| console.log("Seed:", seed); | |
| console.log("Random:", random); | |
| }; | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment