Random Generation of numbers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • y Muralidhar Rao
    New Member
    • Jul 2007
    • 1

    Random Generation of numbers

    Hi, this is murali, Please any one help me to get the code for random genreation of numbers, like to get the recordsin datagrid comes randomly each time i view the output.
  • hariharanmca
    Top Contributor
    • Dec 2006
    • 1977

    #2
    Originally posted by y Muralidhar Rao
    Hi, this is murali, Please any one help me to get the code for random genreation of numbers, like to get the recordsin datagrid comes randomly each time i view the output.

    You can use
    Code:
    rnd()
    function which return Random Numbers

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      The VB Articles section has a couple of entries on the subject of generating random numbers. (Actually, "pseudo-random" numbers. The computer cannot generate truly random numbers.)

      Comment

      • Mague
        New Member
        • May 2007
        • 137

        #4
        If you wanted to generate a random number in between two specific numbers you can use this code

        [code=vbnet]
        Public Function RandomNumber(By Val MaxNumber As Integer, _
        Optional ByVal MinNumber As Integer = 0) As Integer

        ' Initialize random number generator
        Dim r As New Random(System.D ateTime.Now.Mil lisecond)

        ' If passed incorrect arguments, swap them.
        ' Can also throw exception or return 0.

        If MinNumber > MaxNumber Then
        Dim t As Integer = MinNumber
        MinNumber = MaxNumber
        MaxNumber = t
        End If

        Return r.Next(MinNumbe r, MaxNumber)

        End Function
        [/Code]

        I haven't tested it yet. This is for vb.net and if you wanted a proper look here is the site

        Comment

        Working...