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,885 questions

51,811 answers

573 users

How to generate random float in specific range with C#

1 Answer

0 votes
using System;
  
class Program
{
    static void Main() {
        Random rand = new Random();
         
        float min = 2.0f, max = 7.0f;
  
        for (int i = 0; i < 20; i++) {
            Console.WriteLine(rand.NextDouble() * (max - min) + min);
        }
    }
}
  
  
  
  
    
/*
run:
    
4.47292199287234
6.91811802606942
4.13034082768966
5.38790175895575
5.05167335926167
3.27556947584989
5.97031360257897
3.19200239479169
6.17472161081374
6.75219431321705
5.14327246888693
2.99300507735135
3.51005948498382
3.25903790875293
5.50506489328345
2.88300704997173
4.64169119188641
5.93104826981716
6.17522578927466
2.89343020966902
    
*/

 



answered Jun 1, 2022 by avibootz
edited Jul 27, 2023 by avibootz

Related questions

1 answer 110 views
1 answer 160 views
1 answer 124 views
1 answer 145 views
1 answer 126 views
2 answers 115 views
...