SimpleVector - Interactive examples

back

Randomization methods

The randomization methods take two Vector as parameters topLeft and bottomRight which are used to bound the generated random values.

On this page you can drag the topLeft and bottomRight vectors to change the bounds as well as the v1 vector on which we call the .randomizeX, .randomizeY and .randomize methods. Each time these vectors are changed, the page generates 10 vectors to show a sample of output of the methods.

You will notice that the results of .randomizeX all keep the same .y value as v1 but have a .x value between the .x properties of topLeft and bottomRight.

Similarly the results of .randomizeY all keep the same .x value as v1 but have a .y value between the .y properties of topLeft and bottomRight.

Finally, the results of .randomize are independent from the properties of v1 and only depend on the .x and .y properties of topLeft and bottomRight.

Input

v1
x:1, y:1
topLeft
x:-3, y:3
bottomRight
x:3, y:-3

v1.randomizeX(topLeft, bottomRight)

topLeft
x:-3, y:3
bottomRight
x:3, y:-3
random 1
x:1.00365, y:1
random 2
x:-1.6448, y:1
random 3
x:2.25328, y:1
random 4
x:-0.11572, y:1
random 5
x:-2.74526, y:1
random 6
x:2.42985, y:1
random 7
x:-1.73633, y:1
random 8
x:0.7662, y:1
random 9
x:-2.34604, y:1
random 10
x:2.86614, y:1

Input

v1
x:1, y:1
topLeft
x:-3, y:3
bottomRight
x:3, y:-3

v1.randomizeY(topLeft, bottomRight)

topLeft
x:-3, y:3
bottomRight
x:3, y:-3
random 1
x:1, y:-0.39415
random 2
x:1, y:-1.98703
random 3
x:1, y:2.80733
random 4
x:1, y:-1.31576
random 5
x:1, y:-1.28073
random 6
x:1, y:-2.45846
random 7
x:1, y:-1.91194
random 8
x:1, y:-2.29009
random 9
x:1, y:1.82442
random 10
x:1, y:1.17417

Input

v1
x:1, y:1
topLeft
x:-3, y:3
bottomRight
x:3, y:-3

v1.randomize(topLeft, bottomRight)

topLeft
x:-3, y:3
bottomRight
x:3, y:-3
random 1
x:0.2976, y:-2.79992
random 2
x:0.50506, y:-0.31495
random 3
x:2.91653, y:-1.77636
random 4
x:0.47792, y:-2.13346
random 5
x:-1.66989, y:-1.17811
random 6
x:-0.2045, y:1.10436
random 7
x:0.77675, y:-0.53715
random 8
x:-0.35042, y:-2.76422
random 9
x:2.0649, y:-2.54871
random 10
x:-2.29732, y:-0.27334