Results 1 to 5 of 5

Thread: Random Numbers

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Random Numbers

    How can I get a random number that's sometimes negative, and sometimes positive?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    VB Code:
    1. Dim intRnd As Long
    2.  
    3. Randomize
    4. intRnd = Int((999 - -999 + 1) * Rnd + -999)
    5.  
    6. MsgBox intRnd

  3. #3
    jim mcnamara
    Guest
    I'm not sure chrisjk's code is going to work as is.

    Anyway - here's another version

    Code:
    Function num() as integer
       Dim j as single
       dim i as integer
       j = rnd
       if j> .5 then
           i = 1
       else 
           i = -1
       end if
       num = int (rnd*999 +1) * i
    End Function

  4. #4
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    certainly does, tried and tested

  5. #5
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    Thumbs up

    Yes it works, perhaps you should have tested it mcnamara

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