Results 1 to 4 of 4

Thread: (Sorry) Newbie Question Again, Please Answer!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    99

    Talking

    How can I generate a random character or number?

    Thanks.
    ___________________________
    Chris

  2. #2
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    Hi,
    try:
    Code:
    Dim myRandomNumber as integer
    
    myRandomNumber = Int((10 * Rnd)+1)
    This will generate a random number between 1 and 10.
    Change the values to suit your needs.

    Hope this helps

    Shaun
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Rnd returns a random number between 1 and 0

    Rnd*6 a random number between 6 and 0 (and so on)

    Int(rnd*6) returns a whole between 0 and 5.

    asc(int(Rnd*25+65)) returns a random character


    Use RAndomize, to avoid the same random series upon execution

    [Edited by kedaman on 09-01-2000 at 03:54 AM]
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    two things...

    First.

    I use this function:

    Code:
    Private Function Random(ByVal Min as Integer, ByVal Max as Integer) as Integer
    
        Randomize Timer
    
        Random = Int(Val(Rnd * Max) + Min)
    
    End Function
    So

    Code:
        Text1 = Random(1, 6)
    Gives me a random number between 1 and 6, and

    Code:
        Text1 = Chr(Random(65, 90))
    Will give me a random Uppercase Character.

    Second.

    No need to appologise about newbie questions. We've all been there.

    r0ach™
    Don't forget to rate the post

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