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.
FlashKit > Flash Help > Flash ActionScript
Posted on: 08-25-2001, 07:19 PM
View Complete Forum Thread with Replies
Sponsored Links:
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.
View Replies !
View Related
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?)
View Replies !
View Related
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?
View Replies !
View Related
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!
View Replies !
View Related
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.
View Replies !
View Related
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 )
View Replies !
View Related
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.
View Replies !
View Related
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>
View Replies !
View Related
Random Number Between 2 Set Numbers?
I am trying to produce a random number between ohh say 50 and 150 or even between 20,000 and 100,000
The only method I can think of is this:
mynumber = random(1000)+500 for a number between 500 and 1500
but what if I wanted a number between 500 and 1000? am I going to have to do if..then statements or do..while statements until I get the desired numbers?
should be a round number as well..
This seems to be the only way to do it.. That I can figure out anyway... it's a bulky script for such a simple function, but it is accurate.. I think..
on (release) {
do {
randomnum = random(1000)+500;
if (randomnum>1000) {
randomnum = Number(randomnum) - 1000 + 500;
}
} while (randomnum>1000);
}
a random number between 500 and 1000
please help me simplify this problem..
thanks for any help
[Edited by Sintwar on 10-20-2001 at 02:57 PM]
View Replies !
View Related
Random Number Generator & Checking For The Same Numbers
Hi all,
I need to generate 8 random numbers between 0 to 31 when clicking on a button, and put them to dynamic tex fields. I've done this:
on(release)
{
for(var i;i<8;i++)
{
a = Math.random() *100;
b = parseInt(a);
if(b <= 32)
{
c = b;
numbers.push(c);
}
else
{
i--;
}
_root["tagText" + i].text = c;
}
i=0;
}
Where my textfields are called tagText0, tagText1 and so on.
Now I need to check and make sure that none of the numbers are the same. I was thinking to put the generated numbers into an array, and then check this array for duplicate number, and if there is a duplicate then generate a new number for this position, and when no numbers are the same, populate my text fields.
I tried to do this like that:
on(release)
{
var numbers = new Array();
for(var i;i<8;i++)
{
a = Math.random() *100;
b = parseInt(a);
if(b <= 32)
{
c = b;
numbers.push(c);
}
else
{
i--;
}
if(numbers[i] == numbers[i+1])
{
numbers[i+1] = numbers[i+1] + 1;
}
_root["tagText" + i].text = numbers[i];
}
i=0;
}
So I'm only checking two adjacent positions in the array, and I just add +1 if there is an equality. This doesn't work for the whole array and I get duplicate numbers.
Any ideas anybody?
Thanks a lot,
View Replies !
View Related
Generating Random Numbers From 1-20 Matching Every Number Once
So basically I am making a round robin function, for someone, basically a round robin, matches every player with every player, im having alot of trouble with this, its quite difficult
heres an example of the site i've been copying off (his matches are preset though)
The Site I've Been Following
My current code generates about 10 "undefineds" each launch I do
My code gets the input entered (which is the amount of players)
It generates how many players based on that input
my graph I have
is 10 columns long, and 19 rows down
I need to match player
1, vs 2 - 20,
2 vs 3 - 20,
3 vs 4 - 20,
4 vs 5 - 20
5 vs 6 - 20,
6 vs 7 - 20,
7 vs 8 - 20,
8 vs 9 - 20
9 vs 10 - 20,
etc... and repeat until player 19 players player 20, that way all players have played each other
However, I need it to appear randomly across the board, so 1 vs 3, 7 vs 9, 2 vs 20, etc.. but in the end all players play all players
I need help badly with this
my code is below:
Please help, and thank you advance, i've spent alot of time trying to figure this out
Code:
function fncShuffle()
{
return Math.floor(Math.random()*3)-1;
}
function func_round_robin_set_how_many_players()
{
loop = 0;
round_robin_players = round_robin_hmp_input.text;
rrg_XBase = 0;
rrg_YBase = 0;
if (round_robin_players % 2 == 0)
{
if (player_amount > round_robin_players-1)
{
if (round_robin_players < 21)
{
if (round_robin_hmp_input.text.length > 0 && round_robin_players != 0)
{
for (var i:Number = 0; i<190; i++)
{
rr.text_field_mc[i] = null;
rr.text_field_mc[i] = createEmptyMovieClip("rr_mc"+i, i);
var new_txt_field:TextField = rr.text_field_mc[i].createTextField("rr_tf", i, 0, 0, 50, 17);
rr.text_field_mc[i]._x = 160+(75*(rrg_XBase+1));
rr.text_field_mc[i].rr_tf.text = (rrg_XBase+1+n)+" vs "+(rrg_XBase+2+n);
rr.text_field_mc[i]._y = 3+(25*(rrg_YBase+1));
rr.text_field_mc[i].rr_tf.type = "dynamic";
rr.text_field_mc[i].rr_tf.selectable = false;
rr.text_field_mc[i]._visible = false;
rr.text_field_mc[i].onRelease = func_rr_open_profile;
if (rrg_XBase>8)
{
rrg_YBase++;
rrg_XBase = -1;
}
rrg_XBase++;
if (n>rrg_XBase-1)
{
n = -1;
}
n++;
}
// Number of times to shuffle array.
var qtyShuffle:Number = (round_robin_players-1);
// Range array -- starting number and ending number (inclusive).
var rraRange:Array = new Array(1, round_robin_players);
// Calculate delta.
var nbrLen:Number = ((rraRange[1]-rraRange[0])+1);
//trace("nbrLen: "+nbrLen);
// Initialize array to store numbers.
var rraValues:Array = new Array();
// Generate original numerically sorted array.
for (var nbrI:Number = 0; nbrI<nbrLen; nbrI++)
{
rraValues[nbrI] = nbrI+rraRange[0];
}
//trace("rraValues unshuffled: "+rraValues+"
----------------------------------");
// Loop to generate specified quantity of shuffles of array.
rrg_XBase = 0;
rrg_YBase = 0;
var temp_base:Number = new Number(0);
var min:Number = 2;
for (nbrS=0; nbrS<qtyShuffle; nbrS++)
{
rraValues.sort(fncShuffle);
rrg_XBase = 0;
rrg_YBase = 0;
for (var i:Number = 0; i<190; i++)
{
temp_base++;
if (temp_base > (player_amount-1))
{
temp_base = min;
min++;
}
rr.text_field_mc[i].rr_tf.text = rraValues[rrg_XBase]+" vs "+rraValues[temp_base];
rr.text_field_int_1[i] = (rraValues[rrg_XBase])-1;
rr.text_field_int_2[i] = (rraValues[rrg_XBase+1])-1;
trace(rr.text_field_int_1[i]);
//trace(rraValues[rrg_XBase] + ", rrg_XBase< rrg_YBase> "+rraValues[rrg_YBase]);
if (rrg_XBase>(nbrLen-1))
{
if (rrg_YBase > (round_robin_players-2))
{
rrg_YBase = -1;
}
rrg_XBase = -1;
rrg_YBase++;
}
rrg_XBase++;
}
//trace("rraValues shuffle "+nbrS+": "+rraValues);
}
//the rest of it (unimportant), has been removed due to the size being too big
View Replies !
View Related
Generating Random Numbers From 1-20 Matching Every Number Once
So basically I am making a round robin function, for someone, basically a round robin, matches every player with every player, im having alot of trouble with this, its quite difficult
heres an example of the site i've been copying off (his matches are preset though)
http://www.devenezia.com/downloads/r...bin/rounds.php
My current code generates about 10 "undefineds" each launch I do
My code gets the input entered (which is the amount of players)
It generates how many players based on that input
my graph I have
is 10 columns long, and 19 rows down
I need to match player
1, vs 2 - 20,
2 vs 3 - 20,
3 vs 4 - 20,
4 vs 5 - 20
5 vs 6 - 20,
6 vs 7 - 20,
7 vs 8 - 20,
8 vs 9 - 20
9 vs 10 - 20,
etc... and repeat until player 19 players player 20, that way all players have played each other
However, I need it to appear randomly across the board, so 1 vs 3, 7 vs 9, 2 vs 20, etc.. but in the end all players play all players
I need help badly with this
my code is below:
Please help, and thank you advance, i've spent alot of time trying to figure this out
(RED TEXT CAN BE IGNORED, AND IS JUST A PART OF THE FUNCTION)
Code:
function fncShuffle()
{
return Math.floor(Math.random()*3)-1;
}
function func_round_robin_set_how_many_players()
{
loop = 0;
round_robin_players = round_robin_hmp_input.text;
rrg_XBase = 0;
rrg_YBase = 0;
if (round_robin_players % 2 == 0)
{
if (player_amount > round_robin_players-1)
{
if (round_robin_players < 21)
{
if (round_robin_hmp_input.text.length > 0 && round_robin_players != 0)
{
for (var i:Number = 0; i<190; i++)
{
rr.text_field_mc[i] = null;
rr.text_field_mc[i] = createEmptyMovieClip("rr_mc"+i, i);
var new_txt_field:TextField = rr.text_field_mc[i].createTextField("rr_tf", i, 0, 0, 50, 17);
rr.text_field_mc[i]._x = 160+(75*(rrg_XBase+1));
rr.text_field_mc[i].rr_tf.text = (rrg_XBase+1+n)+" vs "+(rrg_XBase+2+n);
rr.text_field_mc[i]._y = 3+(25*(rrg_YBase+1));
rr.text_field_mc[i].rr_tf.type = "dynamic";
rr.text_field_mc[i].rr_tf.selectable = false;
rr.text_field_mc[i]._visible = false;
rr.text_field_mc[i].onRelease = func_rr_open_profile;
if (rrg_XBase>8)
{
rrg_YBase++;
rrg_XBase = -1;
}
rrg_XBase++;
if (n>rrg_XBase-1)
{
n = -1;
}
n++;
}
// Number of times to shuffle array.
var qtyShuffle:Number = (round_robin_players-1);
// Range array -- starting number and ending number (inclusive).
var rraRange:Array = new Array(1, round_robin_players);
// Calculate delta.
var nbrLen:Number = ((rraRange[1]-rraRange[0])+1);
//trace("nbrLen: "+nbrLen);
// Initialize array to store numbers.
var rraValues:Array = new Array();
// Generate original numerically sorted array.
for (var nbrI:Number = 0; nbrI<nbrLen; nbrI++)
{
rraValues[nbrI] = nbrI+rraRange[0];
}
//trace("rraValues unshuffled: "+rraValues+"
----------------------------------");
// Loop to generate specified quantity of shuffles of array.
rrg_XBase = 0;
rrg_YBase = 0;
var temp_base:Number = new Number(0);
var min:Number = 2;
for (nbrS=0; nbrS<qtyShuffle; nbrS++)
{
rraValues.sort(fncShuffle);
rrg_XBase = 0;
rrg_YBase = 0;
for (var i:Number = 0; i<190; i++)
{
temp_base++;
if (temp_base > (player_amount-1))
{
temp_base = min;
min++;
}
rr.text_field_mc[i].rr_tf.text = rraValues[rrg_XBase]+" vs "+rraValues[temp_base];
rr.text_field_int_1[i] = (rraValues[rrg_XBase])-1;
rr.text_field_int_2[i] = (rraValues[rrg_XBase+1])-1;
trace(rr.text_field_int_1[i]);
//trace(rraValues[rrg_XBase] + ", rrg_XBase< rrg_YBase> "+rraValues[rrg_YBase]);
if (rrg_XBase>(nbrLen-1))
{
if (rrg_YBase > (round_robin_players-2))
{
rrg_YBase = -1;
}
rrg_XBase = -1;
rrg_YBase++;
}
rrg_XBase++;
}
//trace("rraValues shuffle "+nbrS+": "+rraValues);
}
for (var i:Number = 0; i<rr.text_field_mc.length; i++)
{
}
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
rr.text_field_mc[i]._visible = true;
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 2)
{
rr.text_field_mc[i+10]._visible = true;
}
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 2)
{
rr.text_field_mc[i+20]._visible = true;
}
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 5)
{
rr.text_field_mc[i+30]._visible = true;
}
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 5)
{
rr.text_field_mc[i+40]._visible = true;
}
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 7)
{
rr.text_field_mc[i+50]._visible = true;
}
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 7)
{
rr.text_field_mc[i+60]._visible = true;
}
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 9)
{
rr.text_field_mc[i+70]._visible = true;
}
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 9)
{
rr.text_field_mc[i+80]._visible = true;
}
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 11)
{
rr.text_field_mc[i+90]._visible = true;
}
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 11)
{
rr.text_field_mc[i+100]._visible = true;
}
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 13)
{
rr.text_field_mc[i+110]._visible = true;
}
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 13)
{
rr.text_field_mc[i+120]._visible = true;
}
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 15)
{
rr.text_field_mc[i+130]._visible = true;
}
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 15)
{
rr.text_field_mc[i+140]._visible = true;
}
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 17)
{
rr.text_field_mc[i+150]._visible = true;
}
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 17)
{
rr.text_field_mc[i+160]._visible = true;
}
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 19)
{
rr.text_field_mc[i+170]._visible = true;
}
loop++;
}
loop = 0;
for (var i:Number = 0; i<((round_robin_players-1)-loop); i++)
{
if (round_robin_players > 19)
{
rr.text_field_mc[i+180]._visible = true;
}
loop++;
}
mla = 0;
rla = 0;
errorbox.text = "";
sch_text._visible = true;
for (var i:Number = 0; i<round_robin_players/2; i++)
{
round_robin_match_text[i]._visible = true;
}
for (var i:Number = 0; i<round_robin_players-1; i++)
{
round_robin_round_text[i]._visible = true;
}
for (var i:Number = 0; i<round_robin_list.length; i++)
{
round_robin_list[i]._visible = false;
}
for (var i:Number = 0; i<round_robin_players/2; i++)
{
match_lines[i]._visible = true;
mla++;
}
for (var i:Number = 0; i<round_robin_players-1; i++)
{
round_lines[i]._visible = true;
rla++;
round_lines[i]._width = 140 * (round_robin_players/2) - ((mla-1) * 64.7);
}
for (var i:Number = 0; i<round_robin_players/2; i++)
{
match_lines[i]._height = 26.5 * (round_robin_players-1) - ((rla-1) * 1.7);
}
}
else
{
errorbox.text = "Please enter a value greater than 0";
}
}
else
{
errorbox.text = "Enter a value no greater than 20";
}
}
else
{
errorbox.text = "You must have atleast "+round_robin_players+" profiles to setup match play for "+round_robin_players+" players";
}
}
else
{
errorbox.text = "Please enter an even number";
}
}
View Replies !
View Related
Random Numbers Calculated To Equal A Specified Number?
here's the idea:
Quote: total = 10000;
mytotal = total;
mytotal = Number(randomnum3) + Number(randomnum2) + Number(randomnum1);
randomnum1 = 3 +""+ random(1+8) +""+ random(1+8) +""+ random(1+8); // makes a random 3### number
randomnum2 = 3 +""+ random(1+8) +""+ random(1+8) +""+ random(1+8); // makes a random 3### number
randomnum3 = 3 +""+ random(1+8) +""+ random(1+8) +""+ random(1+8); // makes a random 3### number
trace(randomnum3 +" "+ randomnum2 +" "+ randomnum1); // shows the 3 random numbers
it does not work. but I wanted to illustrate the concept visually first. now on to the explanation.
What I am trying to is set a specific number (in this example 10000) and then have a series of random numbers generated
to equal 10000 when added together.
Any suggestions?
View Replies !
View Related
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
View Replies !
View Related
Generate Numbers Dynamically
hi there,
i am very new to flash scripting. i want text box in which the numbers start from 500 and increase in a good pace.once it reaches a huge no.(like 50000)the generation stops and the number turns red.
how can i do this.
View Replies !
View Related
Virtual Creditcard/generate Numbers
Hi!
I hope my friend "Eon" read this, my mathematic genie...
Here is my question
I have tried to make a virtual credit card (ice projector)
I want the 16 numbers to generate when the user start the card, different from each other.
When the number is generated I would like to store it in a txt.file (not a database) in some
Way, but the random generated numbers are the first thing to fix.
It would be nice if each number appears after itch other if it’s possibly
Have someone any idea to do that?
Thank swed
http://www.dynamisk.nu/testcard.htm
View Replies !
View Related
Randomly Generate Positive Numbers
I'm rotating a movie clip (a big circle) and want to pick a random number for the rotation position to stop at. I need to create only numbers that are multiples of 4. (I have the increment for rotating it at 1 -- and it's too slow)
--------------
HERE'S MY CODE
I created a random number on the root timeline:
// create random number to use for final position
var ranPos = Math.floor(Math.random()*360)
I've attached this to the mc:
onClipEvent (enterFrame) {
//create variables
turn = _rotation
//start rotation
_rotation = _rotation+1;
//stop rotation at random number
if (turn == _root.ranPos) {
_rotation = turn;
stop();
}
}
I'm a newbie with actionscript so let me know if this approach is totally boneheaded - THANKS
View Replies !
View Related
AS 2 Randomly Generate 3 Unique Numbers
I need to generate 3 unique numbers that will allow me to call from an array that has a list of FLVs with links, title and maybe a description. I know how to make random numbers but i need to know how to make sure that they are not doubling up so i can have [1,8,0] but not [1,8,1]. i will attach all my files and let someone take a look and see if they understand what i am doing.
What i am trying to do is in the chooser.fla is randomly fill the empty movieClips and then i want to build in a timer that will refresh the movieClips with fresh images.
View Replies !
View Related
How To Generate A Group Number?
PHP Code:
function generate(num) {
var total = 0;
var group = []
for(var i=0; i<8; i++) {
group[i] = random(51)+50;
total += group[i];
}
group[8] = num - total;
total += group[8];
trace(group.toString()+", "+total+" == "+num);
}
generate(500);
although this can generate a group of numbers. But it can't limit the last number within 100. So have any better ways to limit all the numbers?
View Replies !
View Related
Generate A Number Form A Input
hi i want to generate passwords to my game and i want to generate the passwords by using the name and the level the player are in
the user enter theyr name in a input the name will be transformed to numbers
"a" = 2;
"b" = 34;
"c" = 594;
"d" = 29;
"e" = 483;
"f" = 59;
"g" = 45;
"h" = 54;
"i" = 877;
"j" = 5;
"k" = 51;
"l" = 24;
"m" = 45;
"n" = 248;
"o" = 55;
........
....
then the name in numbers will be multiply with the level number (138455*4545435)
and the result number will be the password
can someone help me creating this
if u have any idea pleease post a reply
View Replies !
View Related
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
}
}
View Replies !
View Related
Choosing A Random Number (that Isn't The Current Random Number).
I have a loader movie, that randomly chooses a clip to load from an xml list. Sometimes it 'randomly' chooses the same number which makes it look like the loaded clip is mistakenly looping (skipping). Here's the code:
Actionscript Code:
function randomImage() {
if (loaded == filesize) {
fadingPeople._alpha = 0;
numberSelected = random(total);
fadingPeople.loadMovie(image[numberSelected], 1);
}
}
The code runs, waits for x seconds and then fire again. What I'm wondering about is how would I go about telling the random function to choose a random number that's NEQ numberSelected.
Thanks for any help.
View Replies !
View Related
I Need To Dynamically Generate And Print A Report That Varies In It's Number Of Pages
I know some of these things can be done, but I am having trouble putting them all together and getting them to work.
I need to create a program that works as follows:
On the opening page you identify yourself and you are assigned an ID number. The next page allows you to choose any number of 17 catagories. You are then asked questions for each catagory you have chosen. The answers to the questions (some of which can be very long) are formatted and able to be printed to a laser printer. A text (or other type of file) is created and and stored on the server. Two weeks later you can type in your ID number and the program updates to show all of your previous answers and allows you to chose more categories and answer more questions, print all the updated answers, and save a new TEXT file etc.
Some of the issues that I am not clear on is saving the TEXT file to the server to be referenced later and being able to print out a number of pages that varies from one user to another, i.e. one person's set of answers may fit onto 3 pages and another's may need 5 pages.
Any help and direction will be greatly appreciated.
Thanks
View Replies !
View Related
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!
View Replies !
View Related
Random Number Then Delete Number Till Reset
Last edited by pixcels : 2006-10-18 at 22:41.
I am trying to create a type of quiz thing. It is a stand alone move and can not have anything loaded into it.
Problem:
I need a random item from an array, then after the item is displayed I need it to delete itself so that it will not show again. After the array is down to the last item it calls in the array again and starts all over.
Below is code that I have found but it does not delete the array item after it has been show from the array, or restart.
Code:
Array.prototype.shuffle = function() {
var shuffledArray = [];
var copyArray = this.slice(0);
for (var j = 0; j<this.length; j++) {
randomNo = Math.floor(Math.random()*copyArray.length);
shuffledArray[j] = copyArray[randomNo];
copyArray.splice(randomNo, 1);
}
return shuffledArray;
};
testArray = ["1", "2", "3", "4", "5", "6", "7"];
newArray = testArray.shuffle();
//Text area component
theText.text = "newArray = "+newArray
//Button component
theBtn.onRelease = function(){
newArray = testArray.shuffle();
var tempArray = Math.floor(Math.random()*testArray.length)
var totalArray = Math.floor(tempArray+=newArray[0])
var slicedArrary = tempArray.splice(0)
theText.text = "newArray = "+newArray[0]
}
View Replies !
View Related
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!!
View Replies !
View Related
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
View Replies !
View Related
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?
View Replies !
View Related
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.
View Replies !
View Related
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.
View Replies !
View Related
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
View Replies !
View Related
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
View Replies !
View Related
|