I need to create a random -1 or 1 to multiply an already existing number by. Issue is my current random function generates a -1, 0, or 1. What is the most efficient way of doing
why dont you try:
(Math.random() - 0.5) * 2
50% chance of having a negative value with the added benefit of still having a random number generated.
Or if really need a -1/1:
Math.ceil((Math.random() - 0.5) * 2) < 1 ? -1 : 1;