diff options
author | Lee Salzman <[email protected]> | 2021-01-13 01:39:14 -0500 |
---|---|---|
committer | Lee Salzman <[email protected]> | 2021-01-13 01:39:14 -0500 |
commit | e3ada4ed750b976833e3d54a9c1179445289bbf6 (patch) | |
tree | 1a627e13f7473ed4c057d70aa0fd010b5503d17b /host.c | |
parent | 2cc0e7c78045fe2275e7959eb7b9992fe4fd038d (diff) | |
download | enet-e3ada4ed750b976833e3d54a9c1179445289bbf6.tar.gz enet-e3ada4ed750b976833e3d54a9c1179445289bbf6.zip |
implement mulberry32 for PRNG
Diffstat (limited to 'host.c')
-rw-r--r-- | host.c | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -160,6 +160,16 @@ enet_host_destroy (ENetHost * host) enet_free (host); } +enet_uint32 +enet_host_random (ENetHost * host) +{ + /* Mulberry32 by Tommy Ettinger */ + enet_uint32 n = (host -> randomSeed += 0x6D2B79F5U); + n = (n ^ (n >> 15)) * (n | 1U); + n ^= n + (n ^ (n >> 7)) * (n | 61U); + return n ^ (n >> 14); +} + /** Initiates a connection to a foreign host. @param host host seeking the connection @param address destination for the connection @@ -199,7 +209,7 @@ enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelC currentPeer -> channelCount = channelCount; currentPeer -> state = ENET_PEER_STATE_CONNECTING; currentPeer -> address = * address; - currentPeer -> connectID = ++ host -> randomSeed; + currentPeer -> connectID = enet_host_random (host); if (host -> outgoingBandwidth == 0) currentPeer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE; |