DEV Community

Cover image for Working with random numbers in JavaScript

Working with random numbers in JavaScript

Phillip Shim on July 29, 2019

  Unpredictable behavior makes our apps more interesting when done right. For example, imagine card games where you get to keep the same set of ca...
Collapse
 
burakkp profile image
Burak Kucukparmaksiz

Hi Philip,

I am trying to some random number generation, for example, numbers selecting this array => [1 to 9]
numbers generating 9 digits but I want to use each number using just 2 times, not more. How can I do that?

Collapse
 
itscodingthing profile image
Bhanu Pratap Singh

Now I get it 🙂

Collapse
 
shimphillip profile image
Phillip Shim

I am glad you get it!

Collapse
 
jacobmgevans profile image
Jacob Evans

Date.now() * Math.random()

😁

Collapse
 
shimphillip profile image
Phillip Shim

Haha nice one!

Collapse
 
voidjuneau profile image
Juneau Lim

Absolutely didn't know of ceil(). Wow. What have I done until now.
Love the examples. Thank you so much for the post!

Collapse
 
shimphillip profile image
Phillip Shim

Of course, thank you for your kind words :)

Collapse
 
imsikun1 profile image
imsikun

Thank Philip, it's really a good one. Helped me clearing the doubts. Keep it up man

Collapse
 
shimphillip profile image
Phillip Shim

Thanks! I am glad it could help :)