Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
35
rated 0 times [  37] [ 2]  / answers: 1 / hits: 36284  / 12 Years ago, fri, march 16, 2012, 12:00:00

I want a javascript script that choose either value1 or value2 randomly, not between the two values , just the actual values.



Thanks!!!!


More From » random

 Answers
134

The Math.random[MDN] function chooses a random value in the interval [0, 1). You can take advantage of this to choose a value randomly.



var chosenValue = Math.random() < 0.5 ? value1 : value2;

[#86811] Thursday, March 15, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cassies

Total Points: 112
Total Questions: 99
Total Answers: 96

Location: Mexico
Member since Sun, Jul 25, 2021
3 Years ago
;