Randomly 1 or -1
Last updated
Last updated
The above code can be used to get a random value of either 1 or -1.
1 * 2 = 2 - 3 = -1
2 * 2 = 4 - 3 = 1
Getting 1 or -1 can be useful for setting a value to be randomly negative or positive when multiplied by the random value. This can be useful for example for setting a direction randomly.