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 numbers between 1 and N in VB.NET

2 Answers

0 votes
Imports System
 
Public Class Test
    Public Shared Sub Main()
        Dim N as Integer = 50

        For i As Integer = 0 To 20
            Console.Write("{0} ", CInt(Math.Ceiling(Rnd() * N)) + 1)
        Next
    End Sub
End Class
 
 
 
' run:
'
' 8 21 9 10 23 9 36 13 23 2 42 15 22 25 25 34 26 46 14 45 16 

 



answered Nov 30, 2019 by avibootz
0 votes
Imports System
 
Public Class Test
    Public Shared Sub Main()
        Dim N as Integer = 50

        For i As Integer = 0 To 20
            Console.Write("{0} ", CInt(Math.Floor((N - 1 + 1) * Rnd())) + 1)
        Next
    End Sub
End Class
 
 
 
' run:
'
' 2 36 40 45 22 49 19 13 28 50 11 26 31 3 25 38 30 40 1 27 21 

 



answered Nov 30, 2019 by avibootz

Related questions

3 answers 287 views
1 answer 91 views
1 answer 155 views
1 answer 145 views
3 answers 243 views
...