Exact Discrete pseudo-Random Sampling
|
04-08-2020, 08:56 PM
(This post was last modified: 04-08-2020 09:22 PM by Albert Chan.)
Post: #5
|
|||
|
|||
RE: Exact Discrete pseudo-Random Sampling
For random number with small range (say, dice games), bit-mask is simple, and fast.
see O'Neill's benchmark, Efficiently Generating a Number in a Range lua> mt19937 = require 'mt19937' -- Mersenne Twister PRNG lua> rand = mt19937.new(os.clock()) lua> dice = ('%010o'):format(rand(0, 2^30-1)) lua> dice -- upto 10 valid dice throws ! 3746210703 lua> dice = dice:gsub('[07]', '') -- remove invalid throws lua> dice 346213 |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Exact Discrete pseudo-Random Sampling - ttw - 04-08-2020, 03:33 AM
RE: Exact Discrete pseudo-Random Sampling - Paul Dale - 04-08-2020, 05:42 AM
RE: Exact Discrete pseudo-Random Sampling - Albert Chan - 04-08-2020 08:56 PM
RE: Exact Discrete pseudo-Random Sampling - Albert Chan - 04-08-2020, 11:57 PM
RE: Exact Discrete pseudo-Random Sampling - ijabbott - 04-09-2020, 12:54 AM
RE: Exact Discrete pseudo-Random Sampling - Paul Dale - 04-09-2020, 04:53 AM
RE: Exact Discrete pseudo-Random Sampling - Albert Chan - 04-08-2020, 12:34 PM
RE: Exact Discrete pseudo-Random Sampling - ttw - 04-08-2020, 12:53 PM
|
User(s) browsing this thread: 2 Guest(s)