Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

VB Question

  • 28-01-2002 09:12PM
    #1
    Registered Users, Registered Users 2 Posts: 1,182 ✭✭✭


    Just wondering if any of ye code guru's could tell me how to generate a random number between 1 and 100 in VB!?
    Cheers,

    Beef. :)


Comments

  • Registered Users, Registered Users 2 Posts: 707 ✭✭✭d4r3n


    Randomize
    MsgBox Int((High - Low + 1) * Rnd) + Low


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Randomize : MsgBox Int(100 * Rnd) + 1


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Randomize

    Shouldn't that be Randomize Timer ? Wouldn't the radomize reset the seed with the same value all the time? or did they change that for VB?


  • Registered Users, Registered Users 2 Posts: 16,415 ✭✭✭✭Trojan


    Originally posted by Hobbes
    Randomize

    Shouldn't that be Randomize Timer ? Wouldn't the radomize reset the seed with the same value all the time? or did they change that for VB?

    Maybe that's in an older version. Just Randomize should work fine with VB5 or 6.


    Rand(range start, range end) should do fine.
    dim x%, y%
    
    Randomize
    
    x = Rnd
    y = Rand(1, 100)
    

    Al.


  • Registered Users, Registered Users 2 Posts: 1,182 ✭✭✭Beef


    Sher it worked fine! Cheers!(Just Randomize works btw)
    :D


  • Advertisement
  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    Shouldn't that be Randomize Timer ? Wouldn't the radomize reset the seed with the same value all the time? or did they change that for VB?

    Randomize Timer is still allowed for backwards compatibility, but Randomize with no argument is taken to be equivalent.


Advertisement