CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Random Numbers

  1. #1
    Join Date
    Sep 2000
    Location
    Orange County, California
    Posts
    65

    Random Numbers

    heres the code:


    private Sub Form_Load()
    Label1.Caption = Int(Rnd * 10)
    End Sub



    Why is it that everytime that you load that load, label1 always = 7 or the same number, I want to randomly generate numbers!!

    http://visualblind.tsx.org

  2. #2
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: Random Numbers

    from msdn
    Before calling Rnd, use the Randomize statement without an argument to initialize the random-number generator with a seed based on the system timer.



    David Paulson

  3. #3
    Join Date
    Sep 2000
    Location
    Orange County, California
    Posts
    65

    Re: Random Numbers

    I've tried that, it still doesn't work

    http://visualblind.tsx.org

  4. #4
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: Random Numbers

    Try this with a small project. Add a label an a command button to the form. Paste this code.

    private Sub Command1_Click()
    Label1.Caption = Int(Rnd * 10)
    End Sub

    private Sub Form_Load()
    Randomize
    End Sub







    David Paulson

  5. #5
    Join Date
    Sep 2000
    Location
    Orange County, California
    Posts
    65

    Re: Random Numbers

    no, you guys arent getting the picture, i need it on form_load nothing else

    http://visualblind.tsx.org

  6. #6
    Join Date
    May 2000
    Location
    Sacramento, CA
    Posts
    103

    Re: Random Numbers

    I tried
    option Explicit

    private Sub Form_Load()
    Randomize
    Label1.Caption = Int(Rnd() * 10)
    End Sub



    on a simple form with a single default-named label, and it worked fine. Both from the development environment and compiled into an exe.
    Does it work differently on your system?
    (For more information about random number generation, see Knuth, Vol III I believe)


    Dave Straayer
    Varatouch, Inc.
    David H. Straayer

  7. #7
    Join Date
    Sep 2000
    Location
    Orange County, California
    Posts
    65

    Re: Random Numbers


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

Featured