* Adds cxxrandom unit test and fixes interface problems
* Tightens braces
* Adds detection code for Shuffle's seqID/engID
* Adds usage examples for cxxrandom
* Gives cxxrandom objects id ranges, sort of
* Updates changelog
* Updates changelog.txt
* Increases id space for cxxrandom
* Fixes bool distribution error message and improves check
* Adds comment explaining the seeded RNG tests for cxxrandom
* Fixes type problem for 32bit builds
* Reduces loop count a few magnitudes
* Fixes a mistake in test.cxxrandom_seed
@ -4401,7 +4401,7 @@ Native functions (exported to Lua)
adds a number to the sequence
adds a number to the sequence
- ``ShuffleSequence(rngID, seqID)``
- ``ShuffleSequence(seqID, rngID)``
shuffles the number sequence
shuffles the number sequence
@ -4464,7 +4464,7 @@ Lua plugin classes
``bool_distribution``
``bool_distribution``
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
- ``init(min, max)``: constructor
- ``init(chance)``: constructor
- ``next(id)``: returns next boolean in the distribution
- ``next(id)``: returns next boolean in the distribution
- ``id``: engine ID to pass to native function
- ``id``: engine ID to pass to native function
@ -4477,6 +4477,41 @@ Lua plugin classes
- ``shuffle()``: shuffles the sequence of numbers
- ``shuffle()``: shuffles the sequence of numbers
- ``next()``: returns next number in the sequence
- ``next()``: returns next number in the sequence
Usage
-----
The basic idea is you create a number distribution which you generate random numbers along. The C++ relies
on engines keeping state information to determine the next number along the distribution.
You're welcome to try and (ab)use this knowledge for your RNG purposes.
Example::
local rng = require('plugins.cxxrandom')
local norm_dist = rng.normal_distribution(6820,116) // avg, stddev
local engID = rng.MakeNewEngine(0)
-- somewhat reminiscent of the C++ syntax
print(norm_dist:next(engID))
-- a bit more streamlined
local cleanup = true --delete engine on cleanup
local number_generator = rng.crng:new(engID, cleanup, norm_dist)
print(number_generator:next())
-- simplified
print(rng.rollNormal(engID,6820,116))
The number sequences are much simpler. They're intended for where you need to randomly generate an index, perhaps in a loop for an array. You technically don't need an engine to use it, if you don't mind never shuffling.
Example::
local rng = require('plugins.cxxrandom')
local g = rng.crng:new(rng.MakeNewEngine(0), true, rng.num_sequence:new(0,table_size))
@ -42,6 +42,8 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- `tweak` partial-items: displays percentages on partially-consumed items such as hospital cloth
- `tweak` partial-items: displays percentages on partially-consumed items such as hospital cloth
## Fixes
## Fixes
- `cxxrandom`: fixed exception when calling ``bool_distribution``
- `cxxrandom`: fixed id order for ShuffleSequence, but adds code to detect which parameter is which so each id is used correctly. 16000 limit before things get weird (previous was 16 bits)
- `autofarm` removed restriction on only planting 'discovered' plants
- `autofarm` removed restriction on only planting 'discovered' plants
- `luasocket` (and others): return correct status code when closing socket connections
- `luasocket` (and others): return correct status code when closing socket connections
@ -64,6 +66,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- Include recently-added tweaks in example dfhack.init file, clean up dreamfort onMapLoad.init file
- Include recently-added tweaks in example dfhack.init file, clean up dreamfort onMapLoad.init file
## Documentation
## Documentation
- `cxxrandom`: added usage examples
- Add more examples to the plugin skeleton files so they are more informative for a newbie
- Add more examples to the plugin skeleton files so they are more informative for a newbie