Wednesday, 8 September 2010

Random card numbers in Actionscript 3

I was contacted with a question about how to create random numbers for a credit or store card. I came up with the following solution below. I have used a For loop to display four sets of random numbers between one and nine. And have displayed the numbers in four separate dynamic text fields using the appendText property. Instead of having four dynamic text fields you can easily display the random numbers in one text field.

//This function displays a random number between a specified 
//minimum and maximum number.
function randomNumbers(min:Number,max:Number) {
    var Results:Number=Math.floor(Math.random()*max)+min;
    return Results;

//This creates four sets of random numbers and displays
//them in a dynamic text field.
for(var i:uint =0; i < 4; i++){
    var ran1:String = String(randomNumbers(1,9));
    var ran2:String = String(randomNumbers(1,9));
    var ran3:String = String(randomNumbers(1,9));
    var ran4:String = String(randomNumbers(1,9));



  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP