Results 1 to 6 of 6

Thread: Genorating ramdom numbers

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2003
    Posts
    305

    Genorating ramdom numbers

    Hello,im wondering how i can genrate 11 numbers all beggin with 7 example

    i click genrate it says in text1 795656532 click again it says 7139900,many thanks

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Genorating ramdom numbers

    If you always want large numbers like that you could do it like this:
    VB Code:
    1. sNum As String
    2. Dim i As Integer
    3. Dim iMax As Integer
    4.  
    5. Randomize
    6. sNum = "7" '<- You wanted it to start with a 7
    7. iMax = Int(Rnd * 4) + 4 '<- iMax will be a number between 4 and 7
    8. For i = 1 To iMax '<- Loop from 1 to (4-7)
    9.     sNum = sNum & Int(Rnd * 10)
    10. Next
    11. 'sNum will now be a 5 to 8 digit number starting with a 7
    12. Text1.Text = sNum

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2003
    Posts
    305

    Re: Genorating ramdom numbers

    i want it to genrate 16 numbers each time, i tried changing iMax = Int(Rnd * 9) + 9 to diffrent things etc,and it genrators ramdom amound of numbers like

    769591628176
    729741547050
    7660505292077

    some are longer than overs i just want 16 in total many thanks any ideas?

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Genorating ramdom numbers

    Sorry, your first post showed two numbers of different lengths so I thought that was what you wanted. Simply skip the iMax line and change the loop to:
    VB Code:
    1. 'Replace iMax with 15 to generate a 16 digit number (with the initial 7)
    2. Dim i = 1 To [b]15 [/b]

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2003
    Posts
    305

    Re: Genorating ramdom numbers

    sNum As String
    Dim i As Integer
    Dim iMax As Integer

    Private Sub Command1_Click()
    Randomize
    sNum = "7" '<- You wanted it to start with a 7
    iMax = Int(Rnd * 4) + 4 '<- iMax will be a number between 4 and 7
    For i = 15 To iMax '<- Loop from 1 to (4-7)
    Dim i = 1 To 15
    sNum = sNum & Int(Rnd * 10)
    Next
    'sNum will now be a 5 to 8 digit number starting with a 7
    Text1.Text = sNum
    End Sub


    ***

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Genorating ramdom numbers

    Sorry, I accidently typed Dim but I meant For.
    VB Code:
    1. sNum As String
    2. Dim i As Integer
    3.  
    4. Randomize
    5. sNum = "7" '<- You wanted it to start with a 7
    6. For i = 1 To 15
    7.     sNum = sNum & Int(Rnd * 10)
    8. Next
    9. 'sNum will now be a 5 to 8 digit number starting with a 7
    10. Text1.Text = sNum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width