Results 1 to 6 of 6

Thread: The power of RND

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    Hi,

    I'm making a program that will need to randomize two numbers. The problem is that the numbers are not close to each other like 1 to 2. The numbers are something like 2 to 6. But you understand, I only want to random one of those two numbers. If I said:

    intNumber = int((6 * RND) + 1)

    I would get all the numbers in between aswell. I hope you understande what I'm saying here. I only want to random 2 or 6 using the random function. Could you please help?

    Thank you!

  2. #2
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Post

    would this work for you?
    If int((6 * RND) + 1)<3 then
    intNumber = 2
    Else
    intNumber = 6
    End If

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    Hi badgers,

    Maybe I should have been a little more clear in my question. I just used 2 and 6 as an example. Really I want to randondomize one of the numbers 2 3 5 7 and 9. So I'm not too sure that way would work. I will be happy to hear any other ways you may know.

    Thanks

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    I think we are having a problem understanding what you mean by "randomize one of the numbers". Can you give an example of the results you would expect?

    ------------------
    Marty

  5. #5
    New Member
    Join Date
    Aug 1999
    Posts
    15

    Post

    just do like badgers said, but split the resulst into 5 parts

    intNumber = int((5 * RND) + 1)

    then:
    if intNumber = 1 then Result = 2
    if intNumber = 2 then Result = 3
    if intNumber = 3 then Result = 5
    if intNumber = 4 then Result = 7
    if intNumber = 5 then Result = 9

    (a case statement would be easier though)

  6. #6
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    or use this:
    Code:
        Dim Done As Boolean
        Dim myNum As Integer
        Do While Not Done
            myNum = Int((9 * Rnd) + 1)
            If myNum <> 2 And myNum <> 3 And myNum <> 5 And myNum <> 7 And myNum <> 9 Then
                Done = False
            Else
                Done = True
            End If
        Loop
    ------------------
    Visual Basic Programmer
    ------------------
    PolComSoft
    You will hear a lot about it.


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