Thread: Rand() with multiples

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    118

    Rand() with multiples

    I have probably a simple question. I looked in my books for the answer but can't seem to find it anywhere. Could someone please tell me how you can use the Rand() function and come up with a number that is a multiple of another number.

    This is what I mean: Rand()%180+1:step20 - where the step 20 is the multiple of.

    I know the above code does not work but explains what I need quite well.

    Can anyone help?
    "The distinction between past, present and future is only an illussion, even if a stunning one."
    -Albert Einstein

  2. #2
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    try a little fourth grade math

    rand()%9 + 1; generates random numbers from 1-9
    (rand()%9 + 1) * 20; generates random numbers from 20-180 in steps of 20.
    hello, internet!

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    118
    I think I was on cloud nine that day. After I posted I realized how stupid a question that was. Sorry to waste your time.
    "The distinction between past, present and future is only an illussion, even if a stunning one."
    -Albert Einstein

  4. #4
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by Tommaso
    I think I was on cloud nine that day. After I posted I realized how stupid a question that was. Sorry to waste your time.
    oh it wasnt a waste of time, all you have to do is ignore the slight sarcastic tone of mine
    hello, internet!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Find the sum of all the multiples of 3 or 5 below 1000.
    By bdeepak23 in forum C Programming
    Replies: 21
    Last Post: 11-01-2009, 12:22 AM
  2. counting common multiples of 2 numbers
    By j0nnyX in forum C Programming
    Replies: 1
    Last Post: 10-26-2004, 06:20 PM