Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/indiesoftby/defold-splitmix64
SplitMix64 PRNG for Defold: get the same random numbers from the same seeds on all platforms supported by Defold.
https://github.com/indiesoftby/defold-splitmix64
defold defold-game-engine defold-library defold-native-extension lua math random splitmix64
Last synced: about 1 month ago
JSON representation
SplitMix64 PRNG for Defold: get the same random numbers from the same seeds on all platforms supported by Defold.
- Host: GitHub
- URL: https://github.com/indiesoftby/defold-splitmix64
- Owner: indiesoftby
- License: cc0-1.0
- Created: 2021-02-01T08:22:19.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-25T15:46:00.000Z (about 3 years ago)
- Last Synced: 2024-11-02T14:33:26.441Z (about 2 months ago)
- Topics: defold, defold-game-engine, defold-library, defold-native-extension, lua, math, random, splitmix64
- Language: C++
- Homepage: https://indiesoftby.github.io/defold-splitmix64/index.html
- Size: 2.73 MB
- Stars: 18
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-defold - SplitMix64 PRNG
README
[![SplixMix64 Logo](cover.png)](https://github.com/indiesoftby/defold-splitmix64)
# SplitMix64 PRNG for Defold
This extension wraps SplitMix64 in a simple Lua API for the [Defold](https://defold.com/) game engine. The SplitMix64 algo is from [http://prng.di.unimi.it/splitmix64.c](http://prng.di.unimi.it/splitmix64.c), and it's a very fast generator passing BigCrush.
**The main idea of this extension is to get the same random numbers from the same seeds on ALL platforms supported by Defold.**
Take a look at [**the web build 🐲**](https://indiesoftby.github.io/defold-splitmix64/index.html) of the included example, which tests random values from the same seeds.
> Splitmix64 is the default pseudo-random number generator algorithm in Java and is included / available in many other languages. It uses a fairly simple algorithm that, though it is considered to be poor for cryptographic purposes, is **very fast to calculate**, and is **"good enough" for many random number needs**. It passes several fairly rigorous PRNG "fitness" tests that some more complex algorithms fail.
## Installation
You can use it in your own project by adding this project as a [Defold library dependency](http://www.defold.com/manuals/libraries/). Open your `game.project` file and in the dependencies field under project add:
https://github.com/indiesoftby/defold-splitmix64/archive/main.zip
Or point to the ZIP file of a [specific release](https://github.com/indiesoftby/defold-splitmix64/releases).
## Usage
### splitmix64.randomseed(x)
Sets `x` as the "seed" for the pseudo-random generator: equal seeds produce equal sequences of numbers._PARAMETERS_
* __x__ number.### splitmix64.random([m],[n])
When called without arguments, returns a uniform pseudo-random real number in the range `[0,1)`. When called with an integer number `m`, `splitmix64.random` returns a uniform pseudo-random integer in the range `[1, m]`. When called with two integer numbers `m` and `n`, `splitmix64.random` returns a uniform pseudo-random integer in the range `[m, n]`._PARAMETERS_
* __m__ number.
* __n__ number._RETURNS_
* __value__ number - A pseudo-random number.### Example
```lua
splitmix64.randomseed(1)print(splitmix64.random())
print(splitmix64.random(1, 10000))
```### Advanced Usage
You can also globally substitute the built-in `math.random` with `splitmix64`:
```
math.randomseed = splitmix64.randomseed
math.random = splitmix64.random
```