abacus icon indicating copy to clipboard operation
abacus copied to clipboard

Support generating random number in the math expression

Open ghost opened this issue 5 years ago • 1 comments
trafficstars

I am suggesting that we add a rand function to the library.

ghost avatar Oct 20 '20 16:10 ghost

You can add your own functions via the scope:

Abacus.eval("rand() * 10", %{rand: &:rand.normal/0})
{:ok, 4.778221007148446}

I'd rather keep the scope of included functions as low as possible. I could see a global configuration for functions that should be included in the whole project though, something like this:

config :abacus, Abacus, scope: %{
  rand: {:rand, :normal, 0},
  now: {DateTime, :utc_now, 0}
}

narrowtux avatar Oct 20 '20 17:10 narrowtux