Random
random
function random(min: number = 0, max: number = 1): number;
Generates a random floating-point number between two values. The function accepts the following parameters.
min
minimum random value (0 by default)max
maximum random value (1 by default)
Inspired by Processing random() and p5 random() functions.
Usage
To visualize the random values, let's generate a range of numbers using range() function and make each circle to have a random radius with random(1,20)
.
<svg width="400" height="40">
<circle v-for="x in range(0,19)" :cx="x * 20" cy="20" :r="random(1,20)" />
</svg>
Let's also have a random opacity for each circle with random(0.1,1)
<svg width="400" height="40">
<circle v-for="x in range(0,19)" :cx="x * 20" cy="20" :r="random(1,20)" :opacity="random(0.1,1)" />
</svg>
Finally, let's use hue() function to make each circle to have its own color:
<svg width="400" height="40">
<circle v-for="x in range(0,19)" :cx="x * 20" cy="20" :r="random(1,20)" :fill="hue(random(0,360))" :opacity="0.5" />
</svg>
Prior art
https://visualia.github.io/visualia_original/#helper-functions_random