Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




How To Generate Random # That Is Always 16 Digits



Hi,
I need to generate a random number that is always exactly 16 digits long.
I am familar with Random(), but I do not know how to make sure it is always 16 dgits.
Any ideas would be greatly appreciated.
Thanks.
nick



FlashKit > Flash Help > Flash MX
Posted on: 06-18-2002, 02:53 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Using Math.random() To Generate 14 Random Cards
I am relatively new to Actionscript and Flash, but not to web development in general. I have made a small matching game of pairs, where you have to find the pairs and remember where the cards where.

You can see the game here: http://www.mrmen.net/flash.php?game=mrmenmatch

I found a tutorial on how to do this and edited as much as I could after having previous knowledge of PHP and Javascript (as Actionscript has the same C style syntax) and made it display how I wanted it to.

However the code reads from a directory of images. I have 80 images in this directory that I want to use, but as there are only 28 squares (therefore only 14 images are used) it takes the first 14 images in the directory and uses them in a random order to place them in different positions. I want it to be able to randomly select 14 of the 81 images in the directory if possible.

I have posted the whole script below, but the part that I am interested in is where it refers to the location of each image ("http://www.mrmen.net/flash/matchImages/...")


Code:
// Gamefield settings

// EDIT HERE
card_w = 100
card_h = 100
card_wdistance = 10
card_hdistance = 10

// STOP EDIT


card_dw = card_w+card_wdistance
card_dh = card_h+card_hdistance
/*row_card = Math.floor((Stage.width-card_wdistance) / card_dw)
col_card = Math.floor((Stage.height-card_hdistance) / card_dh)*/
row_card = 7;
col_card = 4;
n_card = col_card*row_card%2 == 0 ? col_card*row_card : (col_card-1)*row_card
imgs_n = n_card/2

// CENTER THE IMAGE IN THE CARD
centerImage = function(target){
target.front._visible = false
target.front.container._x -= target.front.container._width/2
target.front.container._y -= target.front.container._height/2
}
// ---------------------------------------------

empty = new Array()
function createCard(n,w,h){
empty.push(n)
this.createEmptyMovieClip('card'+n,n)
with(this['card'+n]){
lineStyle(0,0x000000,100)
beginFill(0xFF9900,120)
moveTo(w/2,0)
lineTo(w/2,h/2)
lineTo(-w/2,h/2)
lineTo(-w/2,-h/2)
lineTo(w/2,-h/2)
lineTo(w/2,0)
endFill()
createEmptyMovieClip('front',1)
front.createEmptyMovieClip('container',2)
front.createEmptyMovieClip('backgr',1)
with(front.backgr){
moveTo(-w/2,-h/2)
lineStyle(0,0x000000,0)
beginFill(0x333333,100)
lineTo(w/2,-h/2)
lineTo(w/2,h/2)
lineTo(-w/2,h/2)
lineTo(-w/2,-h/2)
endFill()
}
front.onEnterFrame = function(){
tot = this.container.getBytesTotal()
car = this.container.getBytesLoaded()
if(tot == car && tot > 200){
this._parent._parent.centerImage(this._parent)
delete this.onEnterFrame
}
}
}
}

selcards = []

function placeImages(){
act_img = 1
for(img=0;img<imgs_n;img++){
for(k=0;k<2;k++){
act = Math.round(Math.random()*(empty.length-1))
this['card'+empty[act]].img_id = act_img
this['card'+empty[act]].front.container.loadMovie("http://www.mrmen.net/flash/matchImages/img"+act_img+".gif")
this['card'+empty[act]].onRelease = function(){
this.rotateCard(0,0)
this.enabled = false
MovieClip.prototype.enabled = false
}
empty.splice(act,1)
}
act_img++
}
}

MovieClip.prototype.rotateCard = function(v,i){
this.operazione = v == 0 ? +0.1 : -0.1
this.incremento = i == 0 ? 100 : 10
selcards.push(this._name)
this.onEnterFrame=function(){
this.incremento += this.operazione;
this._xscale = (100*Math.sin(this.incremento));
if(this._xscale > 0){
this.front._visible = v==1 ? false : true
}
if(this._xscale >= 99 ){
delete this.onEnterFrame
selcards.length < 2 ? MovieClip.prototype.enabled = true : null
v==0 && selcards.length > 1 ? checkCards() : null
}
}
}

function generateGameField(cards,distance,hdistance){
Ypos = card_h/2 + hdistance
Xpos = card_w/2 + distance
for(c=0;c<cards;c++){
createCard(c,card_w,card_h)
if(c%row_card==0 && c>0){
Ypos += this['card'+c]._height + hdistance
Xpos = card_w/2 + distance
}
this['card'+c]._x = Xpos
this['card'+c]._y = Ypos
Xpos += this['card'+c]._width + distance
}
placeImages()
}

generateGameField(n_card,card_wdistance,card_hdistance)

playerScore = 0
playerTries = 0

function checkCards(){

if(this[selcards[0]].img_id == this[selcards[1]].img_id){

playerScore++
displayScore.text = playerScore;
eval(selcards[0])._visible = eval(selcards[1])._visible = false

} else {

eval(selcards[0]).rotateCard(1,1)
eval(selcards[1]).rotateCard(1,1)
eval(selcards[0]).enabled = eval(selcards[1]).enabled = true

}

selcards = []
playerTries++
displayTries.text = playerTries;
if(playerScore == 14) {
finishMessage._visible = true;
} else {
MovieClip.prototype.enabled = true
}

}

How Do I Generate A Random Num From 1 - 5?
hi all,

i have a simple problem that i cant work out.

how do i generate a random number from 1 to 5?

cos the way i do it i always get a 0 (zero) in the result.

thanks

Generate Random Key
I'm trying to generate a random key string

something like this

adfkj4462AJFdkjad44yjJ

it can only have a-z, A-Z, 0-9

i want it to work like this...


ActionScript Code:
myKey = generateAlphaNumKey(10);

and it might print out something like this
dj576JSjk6

the number inside the () is for how many chars will be in the string...

i don't know where to start though...

please help!

How Do You Generate Random.....
How do you generate random battles for rpgs? I don't have the slightest idea where to begin? Would it be easier with tiles, or without?

Please let me know. Again, I don't have a clue where to begin.

Thank you

How Do I Generate And Even Random Number
right now I am generating an random number within a game I am building as such...
dropspot = int(Math.random ()*490+30);
What if I only want the result to be an even number in that range?
Can anyone please help a frustrated flasher?
Thanks

How Do I Generate A Random Number?
I want to create a small actionscript to control the actions of some characters in my movie.

To do this I need a script that every few seconds will assign a random number, say between 1 and 20, to a variable (lets call it var). Then I can use an if statement to test the value of 'var' and trigger an action depending on it's value eg:

if (var==3) {
tellTarget(whatever) {
jump up and down
}
}

The bit I have difficulty with is writing the code to generate this random number. It would also be extremely useful if the interval between the number generation could also be made random so that it didn't happen every x seconds but a bit more unpredictably.

Any ideas anybody? Any good tutes!

How To Generate A Random Number Between X And Y?
i want to generate a random integer between, say, 143 and 398 (just for the sake of argument).. how do i do this?

i know about Math.random... i can use it to generate a random number between 0 and 1 and then i can multiply that number by 398 and round it to an integer to get a number between 0 and 398. but what about between 143 and 398?

~jimmy.

Generate Random Movieclips___huh?¿?
Who knows how to duplicate movieclips randomly without pressing any button??
I just want the movie duplicate a specific movieclip on the root.
Made myself clear??

Thanx
This one.

How To Generate Random Numbers Between 20 And 80
I need to know how to make random numbers between 20 and 80. i don't need the numbers under 20. i tried the random(), but it only selects numbers starting from 0. help me someone.

Generate A Random Number
hello, i want to create a code in my flashmovie. so when i open a page there has to be a random code ... ex. 2ZFRFT87Q3
how can i random create codes that use every letter and number ( 10 characters long )

Generate Random String Of 1s & 0s
I need a smooth stream of about 10 random 1s & 0s that generate from the left & then keep flowing. (view attached).I'm sure this is possible w/actionscript but I don't know how.
I can kind of get it to work here, but you see a slight pause when the movie clip ends/begins.
Any help appreciated!!

Generate A Random Variable?
So i have this text file with 9 variables (more to be added later) named var0, var1, var2, etc.

What I want to do is load the textfile that the variables are contained in and then display one of the variables at random (each var has a little quote in it). So when you visit the home page of my site, you see one quote, and if you refresh, you will see another.

My code right now looks like this:
code:
loadVariablesNum("vars.txt", 3);

str="_level3.var";
num=random(9);
quote=str.concat(num) //produces a string "_level3.var" + a random number that matches a var in the text file

quoteTextField=quote;


the problem is, all that this does is put "_level3.varX" in my text field instead of the quote from the variable _level3.varX.

any ideas? thanks

Generate Random Questions
Hi. I'm making a flash quiz on Flash MX 2004 and was wondering how to make flash generate the questions randomly. Could anyone help me? Thanks.

Generate Random Number (min And Max)
Im new to this whole action script scene, but from what i have seen so far, is that it is very similar to php.

this, i have a problem, i need someway of generating a random number... i dont care if it repeates, i just need to be able to set a min and a max... in php you would use

rand(159,255); to generate a number between 159 and 255

thanks.

How To Generate A Random Maze
anybody know a good tutorial or script for creating a random maze that you can let a player go through.

Generate Random Hex Colour Value?
I am applying a blur filter to many different movieClip instances, but I would like to randomize the colour of each blur.

I am currently passing in a variable 'glowColor' to the GlowFilter object, which has it's hex value specfically set. For example:


ActionScript Code:
var glowColor:Number = 0xFF0000;

glowFilter = new GlowFilter(glowColor, ..., ..., .....);


So - how can I randomly generate a number in Hexadecimal format?

Generate Random Text
I am new to flash and action scripting, and i thought that it would cool to learn by creating a magic 8-ball. I have seen some other tools online that aren't working for me. Anyhow, if there is someone out there that knows how to call text into a text box and randomize that text after a button is pressed.

Generate Random String
how would one generate a random string text of characters of size NUM, and store these in an array. these must be letters and may contain spacing as well.

Generate Random Questions
Hi. I'm making a flash quiz on Flash MX 2004 and was wondering how to make flash generate the questions randomly. Could anyone help me? Thanks.

How To Generate Random Bubbles And/or Balls?
All,

Trying to figure out a way to have a movie clip (a bubble) bounce around the stage randomly. I also need to have the movie clip duplicated so i have aprox. 20 - 50 bubbles. Any help would be much apreciated.

Generate Random Numbers W/o Repeats
I need help doing some simple actionscript to generate a random number between 1 and 20 and not repeat the numbers until all of them have been processed.

Example... I want to put 20 pictures on the screen, one at a time, in 20 different locations (the pictures are all different) until the whole screen is filled up. I know how to do all the coordinates, etc. Just need help generating the numbers.

Any help would be appreciated.

Generate, Random, Place On Grid
Hi All,

This is what I want to do:

Generate a random list of letters from a list of say 8. All letters do not have to be used and repetition is allowed.

There can be repetition, but only at a distance of say 4 places. ie. you could have a,b,c,a given, but not a,b,a.

Depending on what letter is generated an instance/copy of an object gets moved to a specific place on a display grid. So for letter 1 the object is moved to x = 1, y = 0, For letter 2, x = 2, y = 0 and letter 3, x = 3, y = 0 and so on.

Would anyone have any idea as to how to do this?

Thankyou.

Code To Generate Random Actions
Hi people.

I've made 4 Flash Banners and I want them to be played randomly on a web page. What I want is a peice of code on the 1st frame of a blank movie that says to load one of the 4 banners onto the stage, and just to play that banner on a loop.

I think something like this.

on (load){
load random movie

I cant do action script yet!!

Leroy

I Need Code To Generate Random Actions
Hi people.

I've made 4 Flash Banners and I want them to be played randomly on a web page. What I want is a peice of code on the 1st frame of a blank movie that says to load one of the 4 banners onto the stage, and just to play that banner on a loop.

I think something like this.

on (load){
load random movie

I cant do action script yet!!

Leroy

Generate And Retrieve Random Number
I need help generating a random number and retrieving in correctly. I have a flash test shell which displays questions from an xml document. I have it designed in a linear fashion, but want to randomize the questions it retrieves without repeating one.
The question/answers, feedback, and help/hint are also embedded within the question. Here is some of the actionscript I have written:
function setUpStage() {
totalQuestions = Number(QuestionsXML.firstChild.attributes["totalQuestions"]);
CurrentQuestion = "<B>"+QuestionsXML.firstChild.childNodes[Qnum].firstChild.nodeValue+"</B>";
CurrentOption1 = QuestionsXML.firstChild.childNodes[Qnum].childNodes[1].firstChild.nodeValue;
CurrentOption2 = QuestionsXML.firstChild.childNodes[Qnum].childNodes[2].firstChild.nodeValue;
CurrentOption3 = QuestionsXML.firstChild.childNodes[Qnum].childNodes[3].firstChild.nodeValue;
CurrentOption4 = QuestionsXML.firstChild.childNodes[Qnum].childNodes[4].firstChild.nodeValue;
ResponseCorrect = '<font color = "#009900">'+QuestionsXML.firstChild.childNodes[Qnum].childNodes[5].firstChild.nodeValue;
ResponseIncorrect = '<font color = "#ff0000">'+QuestionsXML.firstChild.childNodes[Qnum].childNodes[6].firstChild.nodeValue;
CurrentAnswer = QuestionsXML.firstChild.childNodes[Qnum].attributes["Answer"];
CurrentHelp = "<B>"+QuestionsXML.firstChild.childNodes[Qnum].childNodes[7].firstChild.nodeValue+"</B>";
choiceMade = "";
}

I have a counter which increments the variable Qnum and makes sure that the questions don't exceed the total number of questions in the XML. It works fine as a linear test. I store that in totalQuestions. I would like to randomize the variable Qnum. I am having a heck of a time doing it.

Here is how the XML is formatted:
<Quiz totalQuestions = "7">

<Question Answer = "A">A 30 year old man married a 25 year old woman. She died at age 50 and her husband was so devastated that he cried for years. Ten years after he stopped crying, he died. If he had lived to be 80, how many years was he a widower?
<option choice = "1">1. 25 years</option>
<option choice = "2">2. 50 years</option>
<option choice = "3">3. 10 years</option>
<option choice = "4">4. 30 years</option>
<rationale response="correct">Correct,25 years is the answer.</rationale>
<rationale response="incorrect">That is incorrect. Please try again by clicking close.</rationale>
<help>The answer is old enough to drink and vote.</help>
</Question>
</Quiz>

[MX04] Generate A Random Sound
Hi, I cant seem to find this simple code on the net. could someone post up the basic flash to generate a random sound when button is clicked.

much appreciated Graham.

[MX04] Generate A Random Sound
Hi, I cant seem to find this simple code on the net. could someone post up the basic flash to generate a random sound (1 of 4) when button is clicked.

much appreciated Graham.

Using 3 Different Movieclips To Generate Random Terrain
I am currently creating a side on off road driving game. I have 3 different move clips of varying landscape, called ground0_mc, ground1_mc and ground2_mc. what i want to do is randomly load one of these on runtime so the landscape always looks a bit different everytime you start the game. Also, when you push the forward button the ground movieclip moves backwards to give the illusion of the car moving forward. However, it is not long before the ground movieclip runs out. i have been trying to make it so that one of the other ground movieclips loads when the current ground movieclip gets to a certain place on the stage, so in theory the car could carry on driving forever. Does anyone know how to do this?

How To Generate Random Questions For A Game?
HI... i'm trying to make a "Who wants to be millionaire" flash game. but the questions are allways the same and in the same order. I had an idea: let Actionscript choose 1 question out of 100... so the question DONT repeat.
But the problem is: I dont know how to generate random questions... i just know how to generate random Numbers. plz help

Generate Multiple Random Numbers?
Hi,

I'm trying to generate random numbers using Math.random()* n; but I want the random numbers to reset to something different after a particular event is called. Instead, I've noticed the numbers either buzz away randomly in every frame (when placed inside onEnterFrame), or it picks random numbers once, and then uses those same values over and over (when placed outside the onEnterFrame).

How do i get actionscript to generate new random numbers after each myMC.onPress = function(), or alternatively, after a score changes (like some kind of watch feature?)

How To Generate A Random Score In A Textfield?
i really have a big problem on this part working on my project.. my project is a videoke, that after the user sang the song he/she wants is that at the end, there is a score that will appear(random score from 80-100)... im just a NEWBIE who is seeking for your expert advise... pls help dear brothers and sisters... thanx in advance

Generate Random Tintcolor With SetTint?
Using the following AS I can make my_mc´s color change to a random one:


Code:
var colorT:ColorTransform = new ColorTransform();

addEventListener(Event.ENTER_FRAME, chgColor);

function chgColor(e:Event) {

colorT.blueOffset = Math.round(Math.random() * 510) - 255;
colorT.redOffset = Math.round(Math.random() * 510) - 255;
colorT.greenOffset = Math.round(Math.random() * 510) - 255;

my_mc.transform.colorTransform = colorT;
Can I make a function generate a random color tint to my_mc with setTint the same way, or should I do it another way?

Please Help, How Do I Generate A Random Number Betweek Two Other Numbers?
i want to generate a random number between 200 and 350 for example. what would the code be for that? thanks in advance.

[random Shapes / Fills] Recognize & Generate Them
Hi everyone,

What I'd like to know is if there's an easy way to recognize and also generate fills or shapes (call them as you would understand), NOT MovieClip instances. I need a kind of fill tool as in Photoshop, and others bitmap editing programs (look the icon ;-).

No problem if they must be converted to a MC to latter reference them, but dynamically find the fill of the shape.

There are some examples where the mouse movement is scanned and lines are generated between the points, but I didn't find anyone that generates the fill.

U no what I mean?
Let put our heads together, ah?

Thanks!

Creating A Random Function To Generate Feature
Hello Flashkit Friends,

I am a fairly decent Action Scripter with a question about randomization. The function I want to create would randomly select a number between 1-10, and based on that number it would load one of ten different swfs that would all live on the server. Basically this would allow a different feature article to be loaded when the user comes to the page. Any help in starting this would be greatly appreciated. I have never been able to figure out how to create random numbers in MX.

Thanks in advance,

How Can I Generate An Array Of *exclusive* Random Numbers?
I have been trying to write some code that will produce a list of *exclusive* random numbers between 1 –10.

What seemed very easy has actually taxed me to death!

I have started by setting up a standard “for” loop to push random numbers (generated by Math.random() ) into an array. I then set up another “for loop” within the first to go through all the indexes in the holding array & if the number at that index was not = to the random number generated, push that number onto the end of the array to give an array of exclusive numbers. Problem I have, apart from the fact that the above is about as much good as a chocolate teapot, is how do I know how many times to loop the initial for loop – I can’t tell how long it will take to generate a list of totally exclusive random numbers. If I tell it to loop 10 times it might just come up with 5 exclusive numbers – 3,8,6,4,4,5,3,3,9,1 – only 8,6,5,9,1 all the rest are duplicated.

Any ideas or better ways to achieve this?

Generate A Random Number, To A Certain Decimal Point
Howdy is there anyway to generate a random number (within a range), to a certain decimal point and then display it in a text box?

I know how to do a full number, but am struggling to find out how you get random numbers with decimals.

Thanks in advance.

Generate A Random Number, To A Certain Decimal Point
Howdy is there anyway to generate a random number (within a range), to a certain decimal point and then display it in a text box?

I know how to do a full number, but am struggling to find out how you get random numbers with decimals.

Thanks in advance.

Random Generate In Dynamic Text Field
Hello! Does anyone know how to randomly generate something to display in a dynamic text field. So far I have named the dynamic text field and in the actionscript I have called it, nothing comes up. I have search several places and still have not been able to solve the problem. However before I called the text box I tested my code with the trace function and It display in the output box but not the dynamic text box. Please help.

Example
generateRandom = function() { /* Code I used to call the txt box does not wk.
display.text = Math.ceil(Math.random()*200);
}
function ranEquation(){
...........

or
function ranEquation(){..... /* this was used first to randomly generate and works with the trace function

Thanks

Expeeriment- Using LineTo To Generate An Random Background
G'day people. From now on, day1. I will start contributing to the scene.
Hehe, so after I saw (the old but recovered) thread by Pom, generating random waves, I tought. "Hey! I want to do that with ONLY lineTo"

So after a while of testing (This might not be hard to some) I figured it out.

Annyyways, no complaints about unneccesary stuff and bad coding, you who cant hold yourselfs I WILL! slap you

But your welcome to tell me what you think,

F8 FLA!

Generate Unique Random Blink & Hide
Hello guys.. Im making a game where there are 25 tiles with corresponding questions when you click them. One of the tiles must blink at a time, once the blinking tile was selected it will be hidden and the question will appear. If he answered wrong, the game is over else we will select another blinking tile after answering correctly (but the previous tile is hidden now). So how can i make the tiles blink or change its color using AS? And how i will select the available tiles, where some tiles are already disabled/hidden (already answered)?

here is my pseudocode: (im not yet familiar with AS2 OOP concepts so im will use movie clips here & array to save the selected tiles)


Quote:





select unique random no. from 0 - 25
check if it is in the array1.length not 0 && generated rand. no. is not in the array1
else store generated rand. no. to array1
tell movieclip(array1[0]) goto blink frame
if movieclip(array1[0]) finished blink
goto not blink frame
else
hide the tile




any better idea?

thankz for the one who will reply.. thankz in advance!

AS3 - Generate Random Coordinate Inside Of Triangle
I'm trying to generate random coordinates in a triangle based on the equation I found here: Random_Point_In_Triangle

P = aA + bB + cC

where P is my random point
A,B,C are the points of the triangle
a,b,c are 3 random numbers between 0 and 1 that add up to 1

But I'm having trouble figuring out how to generate 3 random numbers that add up to 1.

Here is what I've come up with, but it seems funky and I'm sure there's a better/correct way:


ActionScript Code:
var a:Number = Math.random();
var b:Number = Utils.randRange( a, 1 );
var c:Number = (1 - b) - a;


Thoughts?

Generate Unique Random Object Blink & Hide
Hello guys.. Im making a game where there are 25 tiles with corresponding questions when you click them. One of the tiles must blink at a time, once the blinking tile was selected it will be hidden and the question will appear. If he answered wrong, the game is over else we will select another blinking tile after answering correctly (but the previous tile is hidden now). So how can i make the tiles blink or change its color using AS? And how i will select the available tiles, where some tiles are already disabled/hidden (already answered)?

here is my pseudocode: (im not yet familiar with AS2 OOP concepts so im will use movie clips here & array to save the selected tiles)


Quote:





select unique random no. from 0 - 25
check if it is in the array1.length not 0 && generated rand. no. is not in the array1
else store generated rand. no. to array1
tell movieclip(array1[0]) goto blink frame
if movieclip(array1[0]) finished blink
goto not blink frame
else
hide the tile




any better idea?

thankz for the one who will reply.. thankz in advance!

Generate A Random Letter From A Dynamic Pool Of Letters?
Hey,

The title says it all really.

I'm making a game where a random letter pops up and the player must press that particular letter on the keyboard within the time limit to gain a success. The more player successes, the larger pool of possible letters shown.

Successes's is a global variable and btnPool holds letters based on the number of successes. Eg, successes = 3, btnPool = a, b, c

I'm an artist really so my brain is fried. I assume its something like...

1. Generate a random number between 1 - 100 and store it.
2. Check how many letters are in btnPool then divde 100 by that number.
3. Allocate the relevant percentage of 100 to each possible letter.
4. Cross reference the stored random number with the percentages allocated to each letter.

And viola? Am i on the right track? Any help with the syntax?

Cheers for any help guys.

Integration, Using A Parabola To Generate Skewed Random Results
ello


I'm trying to write a function that'll take a set of results, assign a probability to each result, and then pick one result at random, according to its probability.

Soooo... I thought I'd calculate the area under sections of a basic parabolic function (y = x^2) to generate the skewed probabilities.

Because of the nature of this curve, the amount of skew is determined by the range of the parabola used, as x tends to zero, the gradient tends to zero, so using 0 - 0.001 would be only slightly skewed. As x tends to infinity, the gradient tends to inifinity, so using values 0 - 100 the probabilities would be heavily skewed.

to recap then, my function would be passed a skew factor, essentially the upper limit of the parabolic graph to use. All I need do is divide the whole range into equal sections according to the number of values and determine the definite integral for each range of the parabola assigned to each of the possible values. Make sense? Good.

integrating y = x^2 gave me y = x^3 / 3

from this I developed the following code:

PHP Code:



vals = ["dog", "cat", "monkey", "horse", "marmotte", "hampster", "yetti", "ant", "mouse", "duck"];
skewfactor = 9;
trace(getProbabilities(vals, skewfactor));

function getProbabilities(vals: Array, skewfactor: Number): Array {
    
    var tot: Number = Math.pow(skewfactor, 3) / 3;
    var range: Number = skewfactor / vals.length;
    
    var probs: Array = new Array();
    var lastbound: Number = 0;
    var count: Number = 0;
    while(count < vals.length) {
        var ubound: Number = (count + 1) * range;
        probs[count] = ((Math.pow(ubound, 3) / 3) - (Math.pow(lastbound, 3) / 3)) / tot;
        lastbound = ubound;
        ++count;
    }
    
    return probs;





and it kinda worked. It produced a set of probabilities which looked like they fell in line with a simple parabola.

My problem is that no matter what skew value (i.e. max range) I pass in, it produces exactly the same results and I'm not sure if my maths is wrong, my theory on the nature of the curve is wrong or if my code is wrong.

Any thoughts, comments or pointers welcomed

Generate Unique Random Object Blinking & Hide
Hello guys.. Im making a game where there are 25 tiles with corresponding questions when you click them. One of the tiles must blink at a time, once the blinking tile was selected it will be hidden and the question will appear. If he answered wrong, the game is over else we will select another blinking tile after answering correctly (but the previous tile is hidden now). So how can i make the tiles blink or change its color using AS? And how i will select the available tiles, where some tiles are already disabled/hidden (already answered)?

here is my pseudocode: (im not yet familiar with AS2 OOP concepts so im will use movie clips here & array to save the selected tiles)





select unique random no. from 0 - 25
check if it is in the array1.length not 0 && generated rand. no. is not in the array1
else store generated rand. no. to array1
tell movieclip(array1[0]) goto blink frame
if movieclip(array1[0]) finished blink
goto not blink frame
else
hide the tile

any better idea?

thankz for the one who will reply.. thankz in advance!

Generate Unique Random Object Blinking & Hide
Hello guys.. Im making a game where there are 25 tiles with corresponding questions when you click them. One of the tiles must blink at a time, once the blinking tile was selected it will be hidden and the question will appear. If he answered wrong, the game is over else we will select another blinking tile after answering correctly (but the previous tile is hidden now). So how can i make the tiles blink or change its color using AS? And how i will select the available tiles, where some tiles are already disabled/hidden (already answered)?

here is my pseudocode: (im not yet familiar with AS2 OOP concepts so im will use movie clips here & array to save the selected tiles)

select unique random no. from 0 - 25
check if it is in the array1.length not 0 && generated rand. no. is not in the array1
else store generated rand. no. to array1
tell movieclip(array1[0]) goto blink frame
if movieclip(array1[0]) finished blink
goto not blink frame
else
hide the tile

I Need To Generate A Random Hexidecimal Number Within The Bounds Of The Color Spectru
Yeah, I'm pretty new at actionscript, and I don't know how to do this. I just found out that I can't use a color variable in parameters of the movie clip's fill methods, so this is what's left...

Generate Random Number Divide By 2 "truncate" (drop Decimal)
Hey everyone, quick qestion aobut actionscript/flash

I have a random number being generated which is as follows


PHP Code:



on (release){
    number = random (enemyHealthMax) / 2;
}




Generally creates a number between 0 and enemyHealthMax...however I then want it to dviide by two. After dividng by 2 though there is a high chance it'll become a decimal number...

I was curious if truncating numbers is possible in acionscript...basically I want it to drop the decimal (So if the number is 2.5 I want it to become 2)

Hope this isn't to confusing, if so please post

Thanks for reading, and your time
SS03

PS - I'm using Flash MX 2004, Actionscript 2.0

Copyright © 2005-08 www.BigResource.com, All rights reserved