+ Reply to Thread
Results 1 to 6 of 6

Random number

  1. #1
    Forum Contributor wmorrison49's Avatar
    Join Date
    09-25-2007
    Posts
    267

    Random number

    Hi everyone,
    I am trying to get this macro to pick a random number between 1 and 1000. It doesn't seem to be doing it, as I have only seen a couple values lower than 250 or higher than 750 out of a lot of trials. Also, it seems to like to pick 706 and 534. Any ideas? Thanks.

    Here's what I used:
    MagicNumber = Int((1000 * Rnd) + 1)

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444
    Hi,

    Adding the randomize function prior to your statement may help

    Please Login or Register  to view this content.
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Registered User
    Join Date
    01-16-2007
    Location
    Near the box
    Posts
    58
    ... it should work...

    try this one yet:

    Please Login or Register  to view this content.
    ? ? ? I like the way how Excel can access system API. Really cool ! ? ? ?

  4. #4
    Forum Contributor wmorrison49's Avatar
    Join Date
    09-25-2007
    Posts
    267
    I tried that first one and it worked like a charm. Thanks! What does "Randomize" do to the code?

  5. #5
    Registered User
    Join Date
    01-16-2007
    Location
    Near the box
    Posts
    58
    Quote Originally Posted by wmorrison49
    What does "Randomize" do to the code?
    Randomize uses number to initialize the random-number generator. Actually setting the new seed value...

  6. #6
    Forum Contributor wmorrison49's Avatar
    Join Date
    09-25-2007
    Posts
    267
    Why didn't mine work before? I thought that RND would do the randomizing for me? And why were 706 and 534 coming up all the time?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1