Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,868 questions

51,791 answers

573 users

How to generate a random float numbers between 0 (0.0...) to 1 (0.9...) in JavaScript

2 Answers

0 votes
for (var i = 0; i < 30; i++) {
    document.write(Math.random() + "<br />");
}
  
 
  
/*
run:
      
0.38637981463271154
0.028066052179060885
0.7186127552670636
0.5900373019856826
0.5022617471920483
0.2967602071326376
0.7732665393232595
0.8861508632815056
0.9960373954129828
0.8967642447348119
0.8508941569297039
0.6812887571487306
0.4347638581662632
0.0693936027706279
0.1897885402960281
0.9002929211462559
0.010860533790359894
0.7005132590381198
0.5183180781299777
0.6186467497169582
0.40135085810990256
0.32019597333198324
0.9305552762654651
0.09925476261321065
0.608603023112703
0.3065006248234289
0.0021230638140179448
0.11417647921287488
0.3528455417642081
0.9494961095034131
      
*/

 



answered Jun 21, 2019 by avibootz
0 votes
for (var i = 0; i < 50; i++) {
    document.write((Math.random()).toFixed(2) + "<br />");
}
  
 
  
/*
run:
      
0.82
0.64
0.94
0.56
0.36
0.84
0.19
0.59
0.28
0.70
0.24
0.38
0.20
0.14
0.36
0.37
0.35
0.36
0.09
0.15
0.94
0.72
0.41
0.10
0.83
0.36
0.99
0.60
0.47
0.29
0.67
0.38
0.00
0.15
0.93
0.06
0.67
0.46
0.60
0.90
0.16
0.15
0.55
0.09
0.19
0.91
0.41
0.01
0.36
0.76
      
*/

 



answered Jun 21, 2019 by avibootz

Related questions

1 answer 166 views
1 answer 171 views
1 answer 168 views
3 answers 313 views
1 answer 168 views
...