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




Random Number



Hi All,

I want to generate a random between 150 and 450.
This number will then be used to set the _x (X Position) of a movie clip on the stage anywhere from 120 to 450.

I have written the following code:

Code:
ran = random(450)+10;
setProperty ("movie_clip", _x, ran);
if (ran<=149) {
setProperty ("movie_clip", _x, 150);
}


This seems to work fine...but at times I do find that the MCs _x position is lesser than 150. 150 is the left edge of the screen and 450 is the right edge. Before and beyond these points, I have other static items which sometimes get covered by the random positioning.
How do I ensure that I generate a number between 150 and 450 only?

All help appreciated



FlashKit > Flash Help > Flash ActionScript
Posted on: 12-06-2002, 12:32 AM


View Complete Forum Thread with Replies

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

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.

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]
}

Random Number Variable That's Different From Previous Number
I have this line of code in my game that works great. However it would work even better if when it the code was executed the next random number was not the same as the one before it. For example if "speech" is on frame 6 when the code is executed I would like the random number to be between 2 and 12 but not 6. (I don't want the same frame to come up as it confuses the kindergarteners and preschoolers using the program.) Here's the code that's working for me now.


ActionScript Code:
speech.gotoAndStop(Math.floor(Math.random()*11)+2);

Random Number
Hi,

I am new to actionscript and am just hoping tbat one of you more experienced user could help me out on this one.

I am trying to get a random number betweeb 1 & 9, does anyone know how to do that?

I know the random() function has been dropped in Flash 5, is there a replacement to that?

Thanks

Random Number
People please help me.

I have this code:

var back = background.getBounds(_root);
minx = back.xmin;
miny = back.ymin;
maxy = back.ymax;
maxx = back.xmax;
function getUniqueRandom (number) {
var numberlist = new array();
for (count=1; count<=number; count++) {
numberlist[count] = count;
this.randomlist = new array();
for (count=numberlist.length-1; count>0; count--) {
picked = math.floor(math.Random()*count)+1;
if (picked<=maxx & picked<=maxy & picked>=miny & picked>=minx) {
this.randomlist[count-1] = numberlist[picked];
numberlist[picked] = numberlist[count];
} else {
//here i want to reset what i did above and get another numbercount+1;
}
}
}
return randomlist;
}
x = new getUniqueRandom(36);
stop ();

What i try to do is it genrates a unique number that is not duplicated. Ok this works fine, my problem is , I have 4 conditions that this random number must meet, if it doesn't meet it, it must choose another one, something is not right wiht my if statement....

Please help... Thanx in advance..

Random Number
Ok this shoulndt be that hard but i cant find anything to tell me how to create random numbers. I want a random number to apper then if n==1 goto lable 'One'. So how do i do random numbers?

Twister

Random Number Once Only
Hi ppl, I have a problem with random number. My game has 2 object "A" & "B" and 4 fixed x and y location. When "A" hit "B", "B" will use random to jump to 1 of the 4 location. I use this code.

location = int(Math.random()*4);

if (location == 0){
x = 0;
y = 3;
}
if (location == 1){
x = 1;
y = 4;
}
if (location == 2){
x = 2;
y = 5;
}
if (location == 3){
x = 3;
y = 6;
}
to determine which location "B" will move. But as I am using hitTest to determine whether "A" will hit "B", there is this problem I face. It seem that random will somethimes generate the same random number (eg. 0, 0, 1, 3, 2, 2). So what happen is that the code (hitTest) will be called twice and "B" will jump 2 times, but I only want it to be called once only. It there anything I can do to change this?
So, bascially my question is how to prevent random number to generate the same number twice.

Pls. help me, and thz for reading. I'm using flash 5.

How Can I Get A Random Number
hi all i have problem with the random number

if i have a movi clip called piont with this action

setProperty ("point", _x, random(100));
setProperty ("point", _y, random(100));

i want it to appear in every location in my movie note
the width is 500 and the hight is 370

??????????

Random Number
i was wondering if anyone knows have a dynamic box, that changes numbers in it. like every second it cycles through 10 different numbers. it just constantly generates randome numbers.

Random Number
Hello All.
I know how to generate a random number to show in textfield or whatever.
What I want to know is how to generate a random number on button click so that everytime the button is clicked it generates a new random number without repeat the previous number.
I.E. You have it set to show numbers in range of 1 to 25.
you click the button and it shows '7' then when the button is clicked again, it picks a different number other than '7'. it can show 7 again, because it's show numbers at random. How do I make it show a different number before repeating a number it already showed? I hope I explained this correctly to get a response.
Thanx

Random Number
Hi All

Can someone please help me with a script that will generate 2 random numbers "between1..10"?

Random Number Between...
Hello,

i would like to find a random integer number allways between -5 and 5. Does anyone know how to do this?

Thanks,
Miguel

Random Number... Please Help
ok i'm sorta a newbi @ action script and need some help please... i need to create a random number between 0 and 400..... but @ times i get below 0 or over 400 can some one help me please this is the code i am currently using :

y = "400";

_global.ycord = random(y);
if (ycord <= 0)
{
_global.ycord = random(y);
}

any help would deffinatly be appreaciated.

Jeff

Random Number
flash mx

how can i generate a random number between 0 and the value of a variable?

Random Number
Hi folks,

I need a varaible to be a random number between 1 and 6.
How do you go about scripting this. I'm sure it's a simple and short answer but i'm new to scripting..

Cheers

Random Number
Hello,

how can i create a random integer number between 1 and 20?

Something like, 1, 2, 3, 4, ....or 20?

Thanks
Miguel

Random Number
I need to create a variable which's number randomaly changes. It must go between 1 and 10, no lower or higher.

At the moment ive been using:

onClipEvent(enterFrame){
variable++
variable++
variable++
etc...
if(variable==10){
variable=0
}


This works fine, but it goes 1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9, etc. I need it to go anything like: 2,4,3,2,2,3,4,6,7,8,5,6,7,8,8,5,4,3,5,6,10,8. The numbers must just come up randomally. Possible? Please?

Random Number
I have an array of movieclips called "charMC".” On a rollover button on each of the mc's I call this function "randomCharSet(activeID)
The “activeID” " parameter is the number of the mc that is been rolled over in the charMC" array.
The function “randomCharSet()”" finds a number between 3 and 7 it then runs a for loop to find another random number times the loop so you come out with an example of 4 0r 5 or 8 random numbers. This is all good but now I want to pass these numbers to the “fadeRan(charMC[ran]);” " function except the number that is in the “var activeID.” ".
So what ever amount of random numbers that is stored in the variable "ran" none of them should be the same as the number stored in “activeID.” "

Ok time for an example:
Lets say the for loop done its thing and

Code:
activeID=19
ran=3 18 12 19 11 12;
now I want to pass all these numbers to this function fadeRan(charMC[ran]); except the number that is equal to “activeID which is 19
Also the same random number should not come up twice like 12 and 12.
See what I'm after can anyone please help with this.

Thanks

Ok Here is the function so far can anyone help with this please.


Code:
function randomCharSet(activeID) {
var activeID = activeID;
ranNum = Math.round(Math.random()*5+3);
for (var i = 0; i < ranNum; i++) {
ran = Math.round(Math.random()*charArray.length);
fadeRan(charMC[ran]);
}
}

Random Number
Hi,

I have one doubt, I have generate the random numbers from 1 to 24. First I got the one random number and process do this number. Next i have play the second level for same file, again generate the random number range 1 to 24. But comes repeat number. And how to avoid the repeat numbers pls help me.

I write the following script like this;

function randrange(min, max) {
var randomNum:Number = Math.round(Math.random()*(max-min))+min;
return randomNum;
}
trace(randrange(1, 24));

could u pls help me.

cheers
senthil

Can You Set A Random Number To Be < Or >?
Just a quick question, anyone know how to code a randome number generater to just be between say... 9.1 and 9.6?

Thanks!
Jason

Random Number
I need to generate a random number between 0 and a variable. In the actionscript dictionary says that math.random() generates a number between 0.0 and 1.0. Is there a way to modify this? I only need to generate integers. The highest number the varible would ever hold would be 19.

Random Number - Less Than 1
I'm using: code: txt2 = Math.round(Math.random()*(y-x))+x; to generate a random number by assingning values to x and y. The problem is, it works fine for values over 1 ... say between 3 and 50.

However, I want it to generate a number between 0.25 and 0.7. For some reason this wont work. Can anyone help?

Thanks.

Random Number
I want to creat a flash to show a number have 3 digit (000 - 999) ! When the flash start the number is changing random ! After 30s the flash is stop and the final number is showed !

How I do it ?

I'm so sorry about my english !
Thanks for your help !

Random Number?
i need to create a rondom number between 1 and 6 that i can set a variable to ...

thanks,
gary

Random Number Of X And Y?
I have this

Code:
if (_root.yellow.hitTest(this)) {
_root.money++;
this._x = -50
this._y = -50
I want to make it so when they grab the coin it moves it to a new random spot in between x=670 y=250

Random Number
Code:
suit = Math.ceil(10*(Math.random()));
...generates a random number between 1 and 10. I want to run it in a loop so that it generates 10 random numbers but excludes any previous numbers generated. In other words gives me the numbers 1 to 10 in a random order.

Random Number Help
I need some action script help I need to get a random number between 1 and 6 put in to a variable I know it has to do with Math.random but i need a number without the decimal points stuff. I know it's either Math.round, Math.ceil or Math.floor but I don't know what one.

HELP Random Number 1-45
i have 45 .mp3s there are named 1.mp3, 2.mp3 (and so on till 45.mp3)

and i need flash to randomly pic one

can you plz fix this code so var rand will pic a random number from 1 to 45

Code:

var rand:Number = (Math.round((Math.random()*my_sound.duration)/1000);
//i need rand to be a random number from 1-45

var mySound:Sound = new Sound();

mySound.loadSound(rand + ".mp3", true);
thanks

[F8] Random Number Help
I need someone to script my flash file here's what I need I have a file that has 15 dynamic text boxs and a button. i need with a click of that button to get a random number in each box but heres the kicker no two dynamic text boxs can have the same number. i have been trying to do this for along time now and my scripting skill is not up to it.

Random Number
Hi, I am looking for some code that will allow me to generate a random number (between 1 and 8), add that number to a list or array (to say that it has already been used). When that code is called again, it generates a random number, however if that number has already been used, it generates a different random number. Finally, if all of the numbers are used, it clears the list, and starts the process again.

Would really appreciate help on this one.

Any help is much appreciated!

Cheers

[F8] Random Number Out Of A Set That Is Used Once
I want to create a random number generator that picks a number out of a set of 25 and then removes the number so it is not picked again.

what is the easiest way to go about this?

Random (number) Help
hi
can anybody help me
In the function random (number)
if for eg. number=56
then it generates any number between 0 and 56
but if want to generate numbers between 56 and 567
what should i do ?
please help me

Random Number
I'm using the following script:


Quote:




pick1=random(22);




Obviously this randomly generates a number between 0 and 21. Is there a way, without using arrays, to use this code but specify which numbers cannot be picked. For example, pick a number from 0-1 but not the value that is held in variable 'a'.

Thanks!

Random Number 1 To 10
I am trying to get the computer to choose a random number between 1 and 10. I tried using
var answer = random(10);
But it was way out of the range. I have seen posts about math.random, perhaps I should be using that?

Random Number Between 0 & 1
I need to know how to have a random number generated between -1 & +1.

The numbers however need to be in the following format : -0.9, -0.36, 0.23, 0.60 (As examples)

Anyone assist?

Random Number
How would i create a random whole number between 10000 & 99999 and put it into a textbox so to form a list?

Random Number
Is there a way to make actionscript 3.0 able to choose a random number out of 200 on every enterframe?

Random Number
I have five numbers

26543
37651
87646
25472
87974

I am not well in scripting kindly assist me how I can play above number randomly and select one of them when I press enter such as lucky draw your prompt response will be highly appreciated


Regards,
sftaa

Random Number
Hi

I need to generate a random key at the end of my image path URL to avoid the image being cached. I'm getting the jpg via loadMovie

like
www.blah.com/images.jpg?s=1234 where 1234 is randomly generated

What's the best way to do this?

Random Number Between X And Y
This is probably a simple function I am over looking.

something like:

PHP Code:



Math.ceil(Math.random()* 5000); 




I want it to pick a number between 2000 and 5000 though.

Random Number Between 1 And 0.
i need a quick and simple action script.
i need a random number genterator of 1 and 0.
basicaly it's like picking heads or tails.
and it needs to put the 1 or 0 into a verable.

Random Number
I am trying to generate a random number between 0 and 34. This is what I have so far, but it doesn't seem to be working in Flash CS3.

import ascb.util.NumberUtilities;
var RandNum:int = NumberUtilities.random(0,34);

any ideas?

Random Number...
Math.random pics a number between 1 and 0 right?
how do i do if i want to randomely pic a number between 0 and 400??

Random Number From 1-500
how do you do a random number from 1-500?

math.round(math.random(1)*10); <-- that only goes from 0-10 lol...

i tried loops and stuff but it didnt work out... :/ i also tried adding a buncha math.randoms but the number was always pretty high...


im using it for this
http://www.toon-network.com/first.html
click on the wack-a-mole title... thatz where im using the random thing... but half the time its off the screen since i used exponents...

Random Number
lets say that when you click on a button the variable
number goes up 1 or 2
but it picks it randomly
how would i do it

Code:
on (release) {
number += random(1) or random(2);
}
?

Random Number.
For generating a random number i used this code


Code:
random(10);
but it generated a number between 10 and 0, but i don't want it to chose the 0

i've found a tutorial where i could use this


Code:
Math.floor(Math.random() * (11 - 1)) + 1
but sometimes didn't work so well !!

Random Number Help
Is there a way for the Math.random code to pick between say 4 options.
So instead of having *100 which would pick any number between 100
could I tell to only pick either 10, 25, 50,100?

Edit: I take it animated gifs dont work for ava's and my sig is defective.

More Random Number Help.
What I have is a two MC's and when they hit a random number is generated. But while they are hitting the number is constantly changing because random is still in effect. Can I make it so when they hit a random number is only chosen once?

Random Number
I'm trying to generate a random number, let's say between 1 and 10

this is the code i'm using....


Code:
Math.ceil(Math.random()*10);
it kinda works but the number 0 is also picked...

but i only wanted the numbers [1,2,3,4,5,6,7,8,9,10]

any tip ??

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