Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Visual Basic (https://www.askmehelpdesk.com/forumdisplay.php?f=469)
-   -   Generating random numbers (https://www.askmehelpdesk.com/showthread.php?t=274003)

  • Oct 26, 2008, 09:29 PM
    bindizzle
    generating random numbers
    Not gernating same number twice in a row
  • Oct 26, 2008, 09:32 PM
    aaj2008

    there is actually a list of numbers on what is called "the table of random digits" I had to use it in Statistics... and it's a table of random digits basically that were computer generated... kinda neat actually
  • Oct 26, 2008, 09:35 PM
    bindizzle

    Hey aaj2008
  • Oct 26, 2008, 09:36 PM
    bindizzle
    here is my problem
    To create a program that generates 7 random numbers display it in 7 labels and there a button if u click it picks out the highest number
  • Oct 26, 2008, 09:38 PM
    aaj2008

    Are you trying to create a computer program? Or are you just using one? Or are you trying to create this on like a TI calculator?
  • Oct 26, 2008, 09:39 PM
    aaj2008
    on a TI calculator there is an application to pick random digits and you can enter how many digits you want and tell it to give you the highest one first...
  • Oct 26, 2008, 09:46 PM
    bindizzle

    I'm trying to create it on Vb 6.0. the random number should be stored in a variable. Here is what I got so far.

    Option Explicit
    Dim random(0 To 6) As Integer
    Dim old(0 To 6) As Integer
    Dim Index As Integer
    Dim I As Integer




    Sub generate()

    For I = 0 To 6
    random(I) = Int(Rnd * 25 + 1)
    If random(I) = old(0 Or 1 Or 2 Or 3 Or 4 Or 5 Or 6) Then
    random(I) = Int(Rnd * 25 + 1)
    End If

    old(I) = random(I)
    lblnum(I).Caption = random(I)
    Next I



    End Sub
    Private Sub btnrandom_Click()
    generate
    End Sub
  • Oct 26, 2008, 09:47 PM
    bindizzle
    This doesn't work. I think I need to create a loop where it loops till it finds a random number that has not been generated before
  • Oct 26, 2008, 09:49 PM
    aaj2008

    I don't really know actually... it looks like it should work to me... umm.. I'm getting tired and about to head to bed but I will do a little research and ask one of my professors in the morning... but yeah the loop might help but not sure
  • Oct 26, 2008, 09:52 PM
    bindizzle

    Thanks for your effort. Appreciate it
  • Oct 27, 2008, 07:10 AM
    aaj2008

    Look at these links.. Should help out bunches

    Non-Repeating random Numbers - Visual Basic - Source Code | DreamInCode.net

    Visual Basic: Random Strings!
  • Oct 27, 2008, 09:30 AM
    KISS

    There generally needs to be a statement like Randomize to reset the seed to make them more random.

    To avoid generating the same number twice, you need to check all the numbers and see if it was generated before.

    I believe the statement is int(25*RND)+1 for 1 to 25. Since RND is a number between 0 and 1. I don't think it includes 1. Check.

  • All times are GMT -7. The time now is 07:17 PM.