A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Random Numbers

  1. #1
    Junior Member
    Join Date
    Apr 2002
    Posts
    5

    Cool

    I am doing an elementary school math game and I need the action scripting code for selecting random numbers.

    I have used the code "variable" = random (10) for numbers
    0-10, but I find that I don't need the 0. Please let me know how I can write the script that only selects numbers between 1-9. I have tried everything. Thanks so much.

  2. #2
    Member
    Join Date
    Mar 2002
    Location
    Auburn, WA
    Posts
    69
    dunno if this will help... but give it a go:

    "variable" = random(10) + 1;

    i believe since random(10) produces 0-9, adding the + 1 will make it 1-10.

    if you don't want decimal numbers (i.e, 1.2345677) then try this:

    "variable" = Math.round(random(10)+1);

    I'm only a newbie so this was my best shot at it.

    Someone please correct me if I am wrong or point out a better way to do it.

    Thanks and good luck.

    --Wyl

  3. #3
    Member
    Join Date
    Mar 2002
    Location
    Auburn, WA
    Posts
    69
    oops....for numbers 1-9 do this.

    "variable" = random(9) + 1;

    or

    "variable" = Math.round(random(9) + 1);

    --Wyl

  4. #4
    Junior Member
    Join Date
    Apr 2002
    Posts
    5

    Thanks so much for the tip. It will float the boat! Have a good week.

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