A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: A bitter Actionscript - [Help]

  1. #1
    XRave tongxn's Avatar
    Join Date
    Apr 2005
    Location
    Somewhere near Here
    Posts
    870

    A bitter Actionscript - [Help]

    I have a "program" here that automatically generate 3 numbers between -100 to 100 (%) so that it's completely random. But I have no idea how to make the Random action start dealing with Variables. Any ideas for it? A simple code would help.

    Regards,
    And hope you had a Merry Christmas

    Tongxn

    P.S. I keep getting into trouble...
    When you actually know what "OMG I have so much homework!" means, you won't want to be me.
    Xrave

  2. #2
    Senior Member
    Join Date
    Jul 2005
    Posts
    692
    I need more information on what your trying to do.

  3. #3
    I dont know what you are trying to do but I hope this helps:

    function randRange(min:Number, max:Number):Number {
    var randomNum:Number = Math.random()*(max-min)+min;
    return randomNum;
    }

    no1 = randRange(100, 100);

    no2 = randRange(100, 100);

    no3 = randRange(100, 100);

  4. #4
    XRave tongxn's Avatar
    Join Date
    Apr 2005
    Location
    Somewhere near Here
    Posts
    870
    just a randomical number chooser.

    I am not asking to much am I?
    When you actually know what "OMG I have so much homework!" means, you won't want to be me.
    Xrave

  5. #5
    Senior Member Shotsy247's Avatar
    Join Date
    Apr 2001
    Location
    Be there in a minute!
    Posts
    1,386
    Quote Originally Posted by tongxn
    I have a "program" here that automatically generate 3 numbers between -100 to 100 (%)
    So do you have a program that does this or are you looking for help building a program that does this? If you want to build this, then Chaos_Blader's post should help.

    Otherwise

    Quote Originally Posted by tongxn
    just a randomical number chooser.

    I am not asking to much am I?
    code:
    myNum = Math.random();



    will give you a random number.

    _t
    I don't feel tardy.

  6. #6
    Registered Deviant
    Join Date
    Sep 2004
    Location
    Cornelius, OR, USA
    Posts
    280
    Code:
    myNum = Math.random();
    will give you a random number between 0 and 1... you need to multiply it by a scale
    Code:
    myNum = Math.random() * 100;
    will give you a number between 0 and 100;
    If you can read this, you're in the right place.

  7. #7
    XRave tongxn's Avatar
    Join Date
    Apr 2005
    Location
    Somewhere near Here
    Posts
    870
    and what is to it a number between -100 and 100?
    When you actually know what "OMG I have so much homework!" means, you won't want to be me.
    Xrave

  8. #8
    Senior Member Shotsy247's Avatar
    Join Date
    Apr 2001
    Location
    Be there in a minute!
    Posts
    1,386
    Between -100 and 100????

    See Chaos_Blader's post. You already have the answer!

    Except add a negative sign in front of the first 100.

    _t
    I don't feel tardy.

  9. #9
    Junior Member
    Join Date
    Dec 2005
    Posts
    20
    If you want to make a random number between -100 and 100 maybe you can fix it with this

    myNum1 = Math.random() * 100;
    myNum2 = Math.random() * 100;
    myNum = myNum1-myNum2;

    Then you will get a a number between -100 and 100
    But the chance that then number is -100, 0 or 100 is very small. (But possible)

    I hope this helped you a little bit.

  10. #10
    Registered Deviant
    Join Date
    Sep 2004
    Location
    Cornelius, OR, USA
    Posts
    280
    Code:
    var myNum = random() * 200 - 100;
    Will get you a number between -100 and 100, but Chaos_Blader had it right, execpt the examples he forgot to put a minus sign in the no1, no2, and no3 examples.
    Quote Originally Posted by Chaos_Blader
    Code:
    function randRange(min:Number, max:Number):Number {
      var randomNum:Number = Math.random()*(max-min)+min;
      return randomNum;
    }
    
    no1 = randRange(-100, 100);
    no2 = randRange(-100, 100);
    no3 = randRange(-100, 100);
    If you can read this, you're in the right place.

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

HTML5 Development Center