Shorthand for random values

#1

I’d like to do something like:

amp: ~1.0

Where the tilde would indicate that a random value between plus or minus 10% of what follows should be used. Use two tildes to indicate 20%, three for 30%, etc. This could save time instead of typing out rand functions.

The tilde probably already means something, but maybe some other symbol or bracketing or something.

0 Likes

#2

Sadly with the current syntax, this isn’t possible.

The best you could get is to create your own function t:

t(1)

You could also support an optional second argument which indicates the +/- percentage in integers:

t(1, 1) # perhaps the default +/- 10% 
t(1, 2) # +/- 20%

The definition of t might look as follows

define :t do |val, perc=1| do
  variance = val * (perc / 10.0)
  rrand(val - variance, val + variance)
end
0 Likes