AS3 Random Numbers Generator
Tutorials

AS3 Random Numbers Generator


Here's an AS3 random numbers generator that I wrote a while back, and I thought I'd share it. I explain how to use it after the code.

var allNumbers:Array = new Array();
var randomNumbers:Array = new Array();
var highest:int = 55;
var pick:int = 6;

for (var i:int = 1; i <= highest; i++)
{
    allNumbers[i] = i;
    if (i == highest)
    {
        getRandomNumbers();
    }
}

function getRandomNumbers():void
{
    for (var i:int = 0; i < pick; i++)
    {
        var rand:int = Math.ceil(Math.random() * (allNumbers.length - 1));
        randomNumbers[i] = allNumbers.splice(rand,1);
        if (i == pick - 1)
        {
            trace(randomNumbers.sort(Array.NUMERIC));
        }
    }
}

// For more ActionScript 3 tutorials, visit http://www.trainingtutorials101.com


Here's how it works:

  1. The highest variable allows to to specify the highest random number that can be chosen. So for example, if you assign a value of 55, then the highest random number you can get will be 55.
  2. The pick variable lets you specify how many random numbers to choose. So for example, if you assign a value of 6, then 6 random numbers will be chosen.
  3. The code is set so that the lowest random number you can get is 1, and that each number only appears once.




- Tutorial - How To Make A Monster Puppet
Two puppet sizes are included in the templates Tutorial at Just Another Project Blog "I have some Mix and Match Monster Puppets to share with you.  This is a fun project that your child can help with.  What does a monster look like? ...

- Tutorial - Make A Ring Holder With A Door Knob
Upcycled ring holder made with a glass or metal drawer knob Tutorial at Mich L. in L.A. Blog "I bet you have a random drawer knob someplace.  (It's probably in a random drawer.)  Wanna make a ring holder?  Here's the DIY. ...

- Tutorial - How To Make A Mosaic House Number With A Cd
This house number will show up at night Mosaic House Number Tutorial at Make it Easy Crafts Blog "Are you ready for another cool recycling project for old CDs?  Well you’ve come to the right place.  This plaque is unique and easy and best...

- Actionscript 3 Number To String Conversion
In this lesson, we're going to learn how to convert numbers to strings in AS3. If you you'd like to do ActionScript 3 Number to String conversions, then you can use the toString() method of the Number class. Here is an example: var myNumber:Number...

- Creating Multiple Textfields And Positioning Them Using Arrays And For Loops In Flash Actionscript 3.0
In this tutorial, we are going to learn how to create multiple text fields and how to position them in different locations using an array and a for loop in Flash using ActionScript 3. Go ahead and create a new Flash ActionScript 3.0 document. Select frame...



Tutorials








.