Results 1 to 7 of 7

Thread: * By a random number

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    3

    * By a random number

    I was just wondering how you get an equation to be multiplied by a random number..

    For example;
    Code:
    Sum = 1 * 1 * (RANDOM NUMBER)
    Label1.Caption = Sum
    Thanks ^^

  2. #2
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: * By a random number

    What language are you using?

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    3

    Re: * By a random number

    Sorry, Visual Basics 6.0

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: * By a random number

    It depends on the range you wnat the random number to be.

    VB Code:
    1. randomize
    2. Sum = 1 * 1 * rnd
    3. Label1.Caption = Sum

    Rnd outputs between 0 and 0.9 look into ways of muliplying that to get ranges of random numbers!

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    3

    Re: * By a random number

    Quote Originally Posted by Pino
    It depends on the range you wnat the random number to be.

    VB Code:
    1. randomize
    2. Sum = 1 * 1 * rnd
    3. Label1.Caption = Sum

    Rnd outputs between 0 and 0.9 look into ways of muliplying that to get ranges of random numbers!
    Thanks^^
    But..(i'v only used vB for a day or two so far), how do i select the range of numbers?

  6. #6
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: * By a random number

    to select range of numbers:
    VB Code:
    1. randomize
    2. Sum = 1 * (rnd * [i]myNum[/i])
    3. Label1.Caption = Sum
    if myNum = 10, then sum could range from 0 to 9.99. if you want to generate a whole number, use CInt or Clng before the parenthesis.

    VB Code:
    1. randomize
    2. Sum = 1 * CLng(rnd * [i]myNum[/i])
    3. Label1.Caption = Sum
    Harsh.
    Show Appreciation. Rate Posts.

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: * By a random number

    Its not so much Vb now, its more mathmatics....

    If rnd outputs 0 - 0.9 and you wnat your range to be 0 to 9 (ie 10 numbers) then you just do this,

    sum = int(rnd * 10)

    Pino

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