dfhack/plugins/cxxrandom.cpp

245 lines
7.1 KiB
C++

Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
/* Plugin for exporting C++11 random number functionality
*Exports functions for random number generation
*Functions:
- seedRNG(seed)
- rollInt(min, max)
- rollDouble(min, max)
- rollNormal(mean, std_deviation)
- rollBool(chance_for_true)
- resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset
- rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use
--(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached)
Author: Josh Cooper
Created: Dec. 13 2017
Updated: Dec. 21 2017
*/
#include <random>
#include <chrono>
#include <unordered_map>
#include <vector>
#include <algorithm>
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
#include <cstdint>
#include <cinttypes>
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
#include <stdio.h>
#include <stdlib.h>
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
#include "Error.h"
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
#include "Core.h"
#include "DataFuncs.h"
#include <Console.h>
#include <Export.h>
#include <PluginManager.h>
using namespace DFHack;
DFHACK_PLUGIN("cxxrandom");
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
#define PLUGIN_VERSION 2.0
color_ostream *cout = nullptr;
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands) {
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
cout = &out;
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
return CR_OK;
}
DFhackCExport command_result plugin_shutdown (color_ostream &out) {
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
return CR_OK;
}
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) {
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
return CR_OK;
}
#define EK_ID_BASE (1ll << 40)
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
class EnginesKeeper
{
private:
EnginesKeeper() = default;
std::unordered_map<uint64_t, std::mt19937_64> m_engines;
uint64_t id_counter = EK_ID_BASE;
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
public:
static EnginesKeeper& Instance() {
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
static EnginesKeeper instance;
return instance;
}
uint64_t NewEngine( uint64_t seed ) {
auto id = ++id_counter;
CHECK_INVALID_ARGUMENT(m_engines.count(id) == 0);
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
std::mt19937_64 engine( seed != 0 ? seed : std::chrono::system_clock::now().time_since_epoch().count() );
m_engines[id] = engine;
return id;
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
}
void DestroyEngine( uint64_t id ) {
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
m_engines.erase( id );
}
void NewSeed( uint64_t id, uint64_t seed ) {
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
CHECK_INVALID_ARGUMENT( m_engines.find( id ) != m_engines.end() );
m_engines[id].seed( seed != 0 ? seed : std::chrono::system_clock::now().time_since_epoch().count() );
}
std::mt19937_64& RNG( uint64_t id ) {
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
CHECK_INVALID_ARGUMENT( m_engines.find( id ) != m_engines.end() );
return m_engines[id];
}
};
uint64_t GenerateEngine( uint64_t seed ) {
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
return EnginesKeeper::Instance().NewEngine( seed );
}
void DestroyEngine( uint64_t id ) {
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
EnginesKeeper::Instance().DestroyEngine( id );
}
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
void NewSeed( uint64_t id, uint64_t seed ) {
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
EnginesKeeper::Instance().NewSeed( id, seed );
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
}
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
int rollInt(uint64_t id, int min, int max) {
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
std::uniform_int_distribution<int> ND(min, max);
return ND(EnginesKeeper::Instance().RNG(id));
}
double rollDouble(uint64_t id, double min, double max) {
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
std::uniform_real_distribution<double> ND(min, max);
return ND(EnginesKeeper::Instance().RNG(id));
}
double rollNormal(uint64_t id, double mean, double stddev) {
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
std::normal_distribution<double> ND(mean, stddev);
return ND(EnginesKeeper::Instance().RNG(id));
}
bool rollBool(uint64_t id, float p) {
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
std::bernoulli_distribution ND(p);
return ND(EnginesKeeper::Instance().RNG(id));
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
}
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
class NumberSequence
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
{
private:
unsigned short m_position = 0;
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
std::vector<int64_t> m_numbers;
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
public:
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
NumberSequence(){}
NumberSequence( int64_t start, int64_t end ) {
for( int64_t i = start; i <= end; ++i ) {
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
m_numbers.push_back( i );
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
}
}
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
void Add( int64_t num ) { m_numbers.push_back( num ); }
void Reset() { m_numbers.clear(); }
int64_t Next() {
if(m_position >= m_numbers.size()) {
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
m_position = 0;
}
return m_numbers[m_position++];
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
}
void Shuffle( uint64_t engID ) {
std::shuffle( std::begin( m_numbers ), std::end( m_numbers ), EnginesKeeper::Instance().RNG(engID));
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
}
void Print() {
for( auto v : m_numbers ) {
cout->print( "%" PRId64 " ", v );
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
}
}
};
#define SK_ID_BASE 0
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
class SequenceKeeper
{
private:
SequenceKeeper() = default;
std::unordered_map<uint64_t, NumberSequence> m_sequences;
uint64_t id_counter = SK_ID_BASE;
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
public:
static SequenceKeeper& Instance() {
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
static SequenceKeeper instance;
return instance;
}
uint64_t MakeNumSequence( int64_t start, int64_t end ) {
auto id = ++id_counter;
CHECK_INVALID_ARGUMENT(m_sequences.count(id) == 0);
m_sequences[id] = NumberSequence(start, end);
return id;
}
uint64_t MakeNumSequence() {
auto id = ++id_counter;
CHECK_INVALID_ARGUMENT(m_sequences.count(id) == 0);
m_sequences[id] = NumberSequence();
return id;
}
void DestroySequence( uint64_t seqID ) {
m_sequences.erase(seqID);
}
void AddToSequence(uint64_t seqID, int64_t num ) {
CHECK_INVALID_ARGUMENT(m_sequences.find(seqID) != m_sequences.end());
m_sequences[seqID].Add(num);
}
void Shuffle(uint64_t seqID, uint64_t engID ) {
uint64_t sid = seqID >= SK_ID_BASE ? seqID : engID;
uint64_t eid = engID >= EK_ID_BASE ? engID : seqID;
CHECK_INVALID_ARGUMENT(m_sequences.find(sid) != m_sequences.end());
m_sequences[sid].Shuffle(eid);
}
int64_t NextInSequence( uint64_t seqID ) {
CHECK_INVALID_ARGUMENT(m_sequences.find(seqID) != m_sequences.end());
return m_sequences[seqID].Next();
}
void PrintSequence( uint64_t seqID ) {
CHECK_INVALID_ARGUMENT(m_sequences.find(seqID) != m_sequences.end());
auto seq = m_sequences[seqID];
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
seq.Print();
}
};
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
uint64_t MakeNumSequence( int64_t start, int64_t end ) {
if (start == end) {
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
return SequenceKeeper::Instance().MakeNumSequence();
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
}
return SequenceKeeper::Instance().MakeNumSequence(start, end);
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
}
void DestroyNumSequence( uint64_t seqID ) {
SequenceKeeper::Instance().DestroySequence(seqID);
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
}
void AddToSequence(uint64_t seqID, int64_t num ) {
SequenceKeeper::Instance().AddToSequence(seqID, num);
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
}
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
void ShuffleSequence(uint64_t seqID, uint64_t engID ) {
SequenceKeeper::Instance().Shuffle(seqID, engID);
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
}
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
int64_t NextInSequence( uint64_t seqID ) {
return SequenceKeeper::Instance().NextInSequence(seqID);
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
}
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
void DebugSequence( uint64_t seqID ) {
SequenceKeeper::Instance().PrintSequence(seqID);
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
}
DFHACK_PLUGIN_LUA_FUNCTIONS {
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
DFHACK_LUA_FUNCTION(GenerateEngine),
DFHACK_LUA_FUNCTION(DestroyEngine),
DFHACK_LUA_FUNCTION(NewSeed),
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
DFHACK_LUA_FUNCTION(rollInt),
DFHACK_LUA_FUNCTION(rollDouble),
DFHACK_LUA_FUNCTION(rollNormal),
DFHACK_LUA_FUNCTION(rollBool),
[Release] cxxrandom v2.0 Major Revision update v2.0 =-=-=-=-= Native functions(exported to lua): -GenerateEngine: returns engine id (args: seed) -DestroyEngine: destroys corresponding engine (args: rngID) -NewSeed re-seeds engine (args: rngID, seed) -rollInt generates random integer (args: rngID, min, max) -rollDouble generates random double (args: rngID, min, max) -rollNormal generates random normal[gaus.] (args: rngID, avg, stddev) -rollBool generates random boolean (args: rngID, chance) -MakeNumSequence returns sequence id (args: start, end) -AddToSequence adds a number to the sequence (args: seqID, num) -ShuffleSequence shuffles the number sequence (args: rngID, seqID) -NextInSequence returns the next number in seq.(args: seqID) Lua plugin functions: -MakeNewEngine returns engine id (args: seed) Lua plugin classes: -crng methods: -init(id, df, dist) :: constructor id - Reference ID of engine to use in RNGenerations df (optional) - bool indicating whether to destroy the Engine when the crng object is garbage collected dist (optional) - lua number distribution to use -__gc() :: destructor -changeSeed(seed) :: alters engine's seed value -setNumDistrib(distrib) :: set's the number distribution crng object should use distrib - number distribution object to use in RNGenerations -next() :: returns the next number in the distribution -shuffle() :: effectively shuffles the number distribution -normal_distribution methods: -init(avg, stddev) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -real_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -int_distribution methods: -init(min, max) :: constructor -next(id) :: returns next number in the distribution id - engine ID to pass to native function -bool_distribution methods: -init(min, max) :: constructor -next(id) :: returns next boolean in the distribution id - engine ID to pass to native function -num_sequence methods: -init(a, b) :: constructor -add(num) :: adds num to the end of the number sequence -shuffle() :: shuffles the sequence of numbers -next() :: returns next number in the sequence Adds missing function exports. Fixes numerous problems I won't go into
2018-04-29 17:23:57 -06:00
DFHACK_LUA_FUNCTION(MakeNumSequence),
DFHACK_LUA_FUNCTION(DestroyNumSequence),
DFHACK_LUA_FUNCTION(AddToSequence),
DFHACK_LUA_FUNCTION(ShuffleSequence),
DFHACK_LUA_FUNCTION(NextInSequence),
DFHACK_LUA_FUNCTION(DebugSequence),
Merge branch cxxrandom Implements helper functions for random number generation. Implemented using C++11 <random> library. Exported Lua Functions: - seedRNG(seed) - rollInt(min, max) - rollDouble(min, max) - rollNormal(mean, std_deviation) - rollBool(chance_for_true) - resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset - rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use --(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached) On branch cxxrandom-rel Changes to be committed: modified: plugins/CMakeLists.txt new file: plugins/cxxrandom.cpp new file: plugins/lua/cxxrandom.lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Squashed commit of the following: commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d Merge: fd9f1982 7aa0608c Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 22 22:17:27 2017 -0800 Merge remote-tracking branch 'origin/temp' into cxxrandom commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 21 21:43:35 2017 -0800 Revises cxxrandom plugin New functions: - seedRNG(ushort seed) --lua exported - GetDistribContainer() --internal singleton - RNG() --internal singleton Summary: - Removed class CXXRNG --Refactored functions that used CXXRNG Changes to be committed: modified: plugins/cxxrandom.cpp commit b42979818a01c1121eace7b1ac14676f5ad5d8b2 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 13:21:49 2017 -0800 Fixes plugin_init() Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process. Changes to be committed: modified: plugins/cxxrandom.cpp commit 753a00a14d9e6519d299638e014abf30509940af Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 20 12:36:17 2017 -0800 Cleans up cxxrandom.cpp DFHack contributions specifies: -spaces instead of tabs, so tabs were converted. -C++ headers before dfhack stuff, so it was done *Also added author name, creation date, and last updated date. Changes to be committed: modified: plugins/cxxrandom.cpp commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Tue Dec 19 22:51:58 2017 -0800 Updates cxxrandom, fixes instance leak deleted header moved definition to cpp file #lethosor fixed singleton instance, no longer a pointer commented out dfhack commands, now only init/shutdown and exported lua functions modified: cxxrandom.cpp deleted: cxxrandom.h commit 821044bef2a0201d0d74192e445c7b29766b42a1 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Sun Dec 17 04:01:11 2017 -0800 Fixes RollIndex and Renames RollNormal Renamed the Normal Distribution RNG function to fit the standard. Now named RollNormal(m,s) Fixed some wonky white space in the lua macro export block. Fixed a stupid mistake with the RollIndex output. (it was outputting 0's) Updated usage details. Changes to be committed: modified: plugins/cxxrandom.cpp commit 1536f43d137b6bc55d55759b43bdccf6ff429b33 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Fri Dec 15 08:50:08 2017 -0800 Fixes/Improves cxxrandom Modified return types Corrected index distribution code commit 8629c7e1509522cb0cc4b649914b90d033cb4763 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Thu Dec 14 19:02:29 2017 -0800 Implements SimpleNumDistribution Exported additional functions to lua. Functions allow the generation of random 0-N index values. Generation promises all unique values [0,N] will be returned once each when generation is run N times. On branch cxxrandom Changes to be committed: modified: plugins/cxxrandom.cpp modified: plugins/cxxrandom.h commit f035f3d20415790542cf83e5e696261661d911f3 Author: Josh Cooper <cooper.s.josh@gmail.com> Date: Wed Dec 13 23:55:39 2017 -0800 Implements cxxrandom cxxrandom was implemented using a singleton. This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome) The singleton interface is wrapped in functions which are exposed for lua usage. Integrated into plugins/CMakeLists.txt On branch dev Changes to be committed: modified: CMakeLists.txt new file: cxxrandom.cpp new file: cxxrandom.h new file: lua/cxxrandom.lua
2017-12-22 23:41:45 -07:00
DFHACK_LUA_END
};