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 between two numbers in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Public Shared Function RandomFloat(ByVal min As Single, ByVal max As Single) As Single
		Dim random As System.Random = New System.Random()
		
        Dim d As Double = (random.NextDouble() * (max - min) + min)
		
        Return CSng(d)
    End Function

    Public Shared Sub Main()
		Console.WriteLine(RandomFloat(20, 30))

		Dim random As System.Random = New System.Random()
        For i As Integer = 0 To 5 - 1
            Console.Write((random.NextDouble() * (32 - 25) + 25) & ", ")
        Next
    End Sub
End Class



' run:
'
' 24.72304
' 28.3061295306804, 27.6442494469901, 27.1661639721907, 30.2325565736892, 27.5743513054095,
'

 



answered Jul 27, 2023 by avibootz

Related questions

2 answers 235 views
1 answer 155 views
1 answer 144 views
3 answers 243 views
1 answer 121 views
1 answer 126 views
...