# Shorthand for random values

**URL:** <https://in-thread.sonic-pi.net/t/shorthand-for-random-values/2139>\
**Category:** Feature Requests\
**Created:** [March 20, 2019, 12:59am UTC](https://in-thread.sonic-pi.net/t/shorthand-for-random-values/2139 "2019-03-20T00:59:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zmatt](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/zmatt/32/673_2.png) [@zmatt](https://in-thread.sonic-pi.net/u/zmatt)\
**Post date:** [March 20, 2019, 12:59am UTC](https://in-thread.sonic-pi.net/t/shorthand-for-random-values/2139/1 "2019-03-20T00:59:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [March 20, 2019, 9:42am UTC](https://in-thread.sonic-pi.net/t/shorthand-for-random-values/2139/2 "2019-03-20T09:42:43Z")

</div>

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

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

```ruby
t(1)

```

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

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

```

The definition of `t` might look as follows

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

```

---

<div class="post-metadata">

**Author:** ![Relaxnow](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/relaxnow/32/2172_2.png) [@Relaxnow](https://in-thread.sonic-pi.net/u/Relaxnow)\
**Post date:** [September 16, 2024, 5:39pm UTC](https://in-thread.sonic-pi.net/t/shorthand-for-random-values/2139/3 "2024-09-16T17:39:14Z")

</div>

```ruby
amp: 1+rdist(0.1)

```
