PCG Random Number Generator

Just found this. I wanna say thanks for the built-in toss method @selimanac. Just a nice little QoL perk that is greatly appreciated.

7 Likes

Same here, I was struggling with my html5 version and the random stuff that was absolutely NOT doing what it was supposed toā€¦ I was about to burn my house.

Thank you very much @selimanac , this extension is amazing and saved my house.

(anyone using random numbers should give it a try)

6 Likes

DnD-style dice roller added. One of my prototypes requires rolling a DnD-style dice, so I implemented it in the generator.

rnd.dice(roll, type)

DnD style dice roller.

PARAMETERS

  • roll (int) - Roll amount
  • type (enum) - Type of the dice.
    rnd.d4 : D4: four-sided die.
    rnd.d6 : D6: six-sided die.
    rnd.d8 : D8: eight-sided die.
    rnd.d10 : D10: ten-sided die (0-9).
    rnd.d12 : D12: twelve-sided die.
    rnd.d20 : D20: twenty-sided die.
    rnd.d100 : D%: percentile die (0-10-20ā€¦90).

RETURN

  • result (table) - Dice results
  • total (int) - Total amout of dice results

EXAMPLE

local result, total = rnd.dice(2, rnd.d10)
6 Likes

Whatā€™s the thinking behind the type enum? I would probably have gone for a rnd.dice(roll, sides).

rnd.dice(2, 6) + 2 -- 2D6+2
rnd.dice(1, 4) -- 1D4
-- etc

Might also be interesting to have it return the individual rolls as a second value? For instance if you want to roll a number of dice and discard values above/below a certain value. Or if the function always returns a table of values and then you can apply functions such as sum(), discard() etc (I begin to smell feature creep though!)

1 Like

A d10 (ranges from 0 to 9) and a d100 (ranges from 0, 10, 20, ā€¦ 90) are different. They can be handled, of course, but I want it to be clear to the developer. The library also includes a toss (coin flip) and a 6-sided die. Also, there is already rnd.range(min, max). These dice rolls are just fun shorthandsā€¦

Iā€™m not sure if I got this one correct, but it returns every dice roll as a table as the first return argument and sum as second.
I left everything else to the developer. I thought it was a good thing because, as you said, there are lots of possibilities.Iā€™m actually not that good as a dungeon master and donā€™t know all the circumstances. :slight_smile:

1 Like