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




Math.Random



I am having trouble, actually I don't know where to start. I am trying to use the Math.random command but I don't know how specify it to become a whole number. I also don't know how to specify the range of the random number that I'd like to get.

For the sake of argument I would like to retrieve a value from 1 to 3.

Please help, I'm just trying to get accustomed to AS

Thanks



FlashKit > Flash Help > Flash ActionScript
Posted on: 02-14-2002, 02:32 AM


View Complete Forum Thread with Replies

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

Controlling The Odds Of Math.floor(Math.random()
Hey,
Is there a way to set a random number in a array to showup maybe once a day. Or every 5000 views or loops, or something like that. I would love to be able to control the odds of a array. Cheers!

ActionScript Code:
var pic_array = new Array();
    pic_array[0] = "images/1";
    pic_array[1] = "images/2";
    pic_array[2] = "images/3";
    pic_array[3] = "images/4";
    pic_array[4] = "images/5";
    pic_array[5] = "images/6";
    pic_array[6] = "images/7";
    pic_array[7] = "images/8";
    pic_array[8] = "images/9";
    pic_array[9] = "images/10";
    pic_array[10] = "images/11";
    pic_array[11] = "images/12";
    pic_array[12] = "images/13";
    pic_array[13] = "images/14";
   
    ranNum = Math.floor(Math.random()*pic_array.length);
    holder_mc.loadMovie(pic_array[ranNum]+".jpg");

Math.round(Math.random()*4)+1
Will this return values of 1 to 5 (inclusive).

If not, anyone know how to get random whole numbers 1 to 5?!

Cheers.

Dongle

Var I = Math.round(Math.random()*1)
this should return either 1 or 0?

but it seems to be returning something else as well and i dont know what it is???

function startXPos() {
var i = Math.round(Math.random()*1);
_root.test1 = i;
_root.test2 = t;
return i;
}

i have this just after

if (startXPos() == 0) {
startX = -500;
endX = 750;
} else if (startXPos() == 1) {
startX = 750;
endX = -500;
} else {
startX = 0;
endX = 0;
}

_root.test3 = startX;
_root.test4 = endX;

As far as i am aware this should never return 0 for these two values but it does?!?

can someone please tell what im doing wrong here?

Math.round() Or Math.random()
Is it better to use Math.round() or Math.random() reason I am asking I think I read somehwere that one was better. My problem is that I have a number of movie clips that are attach dynamically. They move randomly on the stage but for some reason they just stop moving randomly.. I think there was a post somehwere about that but cannot seem to find it.

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
}

}

Has Anyone Tested How Random Is The Math.Random() Function?
Just wondering whether anyone out there has ever run any tests on how random the Math.Random() function is as a random number generator?

I've been asked me to test it to prove that it is random and it seems a pointless waste of time, so I'm hoping to get evidence from elsewhere to convince the powers that be that there's no need to run the tests.

I've googled for it but come up with nothing so I'm hoping there might be someone out there who has already done the research?

Math.random With Non-repeating Random Choices
I'm trying to create a puzzle game wherein pieces pop up randomly, but each piece will pop up randomly only once. The code I've used to start is:


ActionScript Code:
pics.gotoAndStop(Math.floor(Math.random()*4));

where I've placed a movie clip containing all of the pieces on the main timeline and named it "pics".
How can I make it such that each piece is eliminated from random pick once it has been picked?

Math.random()
hi ... does anyone know how i can generate a random number between -5 and 5 using math.random() ?
its got to be easy but i cant work it out ...

thanks ... thesquirrel

Math.random();
Hey guys big problem here. I am trying to use the Math.random(); command to generate a 1 or a 0. What I have so far is in the first frame of the MC, on actionscripts:

number = "Math.random()";

Then next frame I have stop. The text field in the next frame is dynamic and the variable is set to "number". When I go to export this, all I get is a blinking "C"...I guess C stands for confused . Also when I do a trace on the variable "number", all it returns is "Math.random()".Anyways, I am stumped and am wondering what I am doing wrong.

I thank you for any help in advance.
[Edited by dracen on 01-29-2002 at 09:48 PM]

Math.random
Hehehe.
I program for C++ JAVA and VB.

but i still cant figure out how Math.random works in
FlashActionScripting.

by reading these here threds.
so IF anyone has a .fla out there, i could DONWLOAD
it would be great,

http://www.JediMinds.Com

Math.random
I need to know how you can use the following script and have it round to the nearest whole number.

variable = [math.random() *12]

Thanks!

Math.random & If
Should this work in flash MX actionscript?


FRAME 1
display = Math.round(Math.random()*2);

FRAME 2
if (display == 0) {
loadVariables("00_ComputerText/00_Home.txt", "");
}
if (display == 1) {
loadVariables("00_ComputerText/00_01.txt", "");
}
if (display == 2) {
loadVariables("00_ComputerText/00_02.txt", "");
}


I had used it in flash 5 but can't seem to get it in MX.
Actionscript dictionary says:
--------
Math.random
Availability
Flash Player 5. In Flash Player 4, the methods and properties of the Math object are emulated using approximations and may not be as accurate as the non-emulated math functions supported by Flash Player 5.

Usage
Math.random()

Parameters
None.

Returns
A number.

Description
Method; returns n, where 0 <= n < 1.
--------

I am essentially randomly picking a txt file by picking a random number. Any other alternate actionscript methods are welcome suggestions.


Thank you thankyou.

Math Random
hey guys. i have a background image on my main page. i'm going to place that background image into mc and then add 4 frames to the mc. on the first frame i want it to choose a random frame to go to and then to go to the frame (in the mc). each frame will have a different background image. what i want is to know what code i should use for it to choose the random frame!

thanks

HELP Math.random
Hey there!
I'm making a game thats like a high tech PONG, and when ever the player starts a new game I want the ball to start in a different position. This is the code I'm using but I guess I don't know how to use it.
code: _x = Math.random()400-600;
_y = Math.random()200-300;
I want it to randomly pick an _x position HIGHER than 400x and LESS than 600x. And I want the _y to randomly pick HIGHER than 200y and LESS than 300y. Can someone help?

Thanks ahead of time, and here's a donut.

Math.random()*100+200
I use this:
code: Math.random()*100+200
a lot but i don't understand it. How does it only choose a random number between 100 and 200?

It doesen't make scence to me.

Thanks


Math.Random Help?
Okay, so maybe it's late or maybe I've just been working on this project too long... but I can't seem to remember how to use the math.random function to do what I'm trying to do. I'm using Flash MX and I have a movie clip which will eventually have 24 labeled keyframes (beta1, beta2, beta3, ...) as marking points. When the movie clip starts playing I want to randomly jump to one. How do I use Math.random to make this happen? I know it also Math.floor but I can't seem to remember how the two go together! Please advise. To help you visualize the idea, the movie is attached. Note that only half of the markers are labeled so far! Thanks for your help in advance.

Sleep weary,
M. Vaughn

Can't Get Math.random...
The code below will display all the pictures where I want them on the stage but I can't get them to randomly display the pictures. I know that whatever I am doing wrong is simple but I don't get it!!!

// list of pics
picList = ["e1_mc","e2_mc","e3_mc","e4_mc","e5_mc","e6_mc","s 1_mc","s2_mc","s3_mc","s4_mc","s5_mc","s6_mc"];

x = 0;
y = 0;

for (i=0; i<picList.length; i++) {
myNum = int(Math.random()*picList.length);
this.attachMovie(picList[i], "p"+i, 5+i);
this["p"+i]._x = x*132+35;
this["p"+i]._y = y*62+30;
x++;
if (x > 2) {
x = 0;
y++;
}
}

stop();

Using Math.random()
using math.random is it possible so that it doesnt go below 30?

i am using it to tween alpha and it fades in and out depending on the random number but i never want it to drop below 30? but from 31-100 it is random.
thanks

Math Random From -6 To 6 ? How Do You Do It
Hi at the moment im making a game, the problem that i have is that i cant make a math random from inbetween (-6) to (+6) all i can do is say

random(6)

or

Math.random() * 6

but i dont know how to make the random number be inbetween the negative aswell.

Math Random
I am try to send my movieClip popped1 to a random frame between 2 and 4.



on (release) {
var i = Math.random()*2+2;
popped1.gotoAndPlay(i);
}

???????not working???????

Math.random()
Could someone please give me an example of how to use Math.random() correctly. I know that the random(n) - function gave me a number between 0 and n-1. But somehow Math.random() gives me a number between 0 and 1. Now how ist the correct example how to use it If I for example want a number between 1 and 5.

Waitin eagerly for the answer

Math.random()*
is there a way 2 use Math.random and define the range of randomness ?

4 example: get a random # between 20 and 50. cuz usually it starts @ 0.

thnx, !!~~

Math.random
error





























Edited: 08/18/2008 at 01:49:33 PM by samunick

Math.random
hi Married woman i'm Luciano how are you i hope you fill good ,i have a problem to store a number inside an Array.
I would like to store some number in an Array but i can't resolve this problem because when i randomize a number i'm not to be able to diversify a number stored inside in a array.
I would like to know if is possible to resolve this problem because i try a lot of time but i have still not resolve this problem because when i activate a trace and when i check a number inside an array i reply two number equal
for semplify my problem i can attach my code:

so i'm glad to inform that you are very kind to they give to me straight;

thanks a lot Luciano







Attach Code

var Leng:Number = tempArray.length;
for (var f:int = 0;f< Leng; f++){
var RndNumA:Array= [];
var RndNumB:* = Math.floor(Math.random() * Leng );
if(RndNumA[f] != RndNumB)
RndNumA.push(RndNumB);
}

Math.random()
hello people how can i place my letters in a different position everytime the game starts and the letters will not appear in the same position? right now i can make them appear in different positions but sometimes they will appear in a same position. can anyone help me solve this problem?

i got the fla file attached here. thx

Math.random
ive got a load of small thumbnail images in a library and i want to display a random 50 of them on the stage when a generate button is pressed. I was going to do it by placing 50 empty movie clips on the stage and then have each one of them load a random one of the jpegs using a code a bit like below:

on (release) {

filename = ["thumb1.swf", "thumb2.swf", "thumb3.swf", "thumb4.swf", "thumb5.swf", "thumb6.swf",etc.....];

i = filename.length;
k = Math.floor(Math.random()*i);
loadMovie(filename[k], "_root.screen_mc");
}

However im not sure how to adapt this to load into 50 empty mcs at once without just copy and pasting it 50 times!!!!!!!!! There is also the problem of duplicates ( different mcs showing the same thumbnail) ...im not too worried about this but if there is a way around it id love to know how.

THANKS ALL.

Math.random()
does math.random return a 0 or a 1, or does it return 0,0.1,0.2...1?
just curious as im using a code with (math.random()*10)+5;
but if it only returns a 0 or a 1 its not that random as it will either be 5 or 15,
just wondering is all!
thanks

Math.random()
besides Math.random(), is there another way to specify a range of numbers, say between 0-100,

Math.random()
hello people how can i place my letters in a different position everytime the game starts and the letters will not appear in the same position? right now i can make them appear in different positions but sometimes they will appear in a same position. can anyone help me solve this problem?

i got the fla file attached here. thx

Math.random()
trying to generate random numbers of 1,21,41,61,81,101 -- can ONLY be those numbers.

this code works: Number(random(6)*20)+1;

but isn't this code old?
what would the new MX code be?

Math.floor(Math.random() * 20) + 1; // help

Math.random With
Hello all,
I have to move a bicycling charachter animation forth and back around the screen; I wish to simulate its movement scrolling the scenario on the back (green and pleasant mountains, for example).
I'm wondering if it's possible to get an ever-changing scenario dropping mountains shapes a bit out of the stage and letting them come inside, in a continous sequence, WITH A RANDOM APPEARANCE: I thought I can do it with populating an array with a pack of library symbols, and combining it with a math.random - function, but I'm a little stuck with it: must I use also a for cycle?

I don't if this is the right approach. Anyway any help will be very appreciated

thanks in advance
Ninetta

Math.random()
I'm a little curious about the Math.random function and how flash generates random numbers? I made a simple .swf that simulated the roll of a 2 dice, but how random is it really? It just doesn't seem to be truly random. If anyone knows anything about this I would like to know.

Where Do I Put The Math.Random()
So i have been working with the help of a bunch of people from here on the following code.

Code:

var magnet_radius:Number = 120;
var coefficient:Number = 0.09;
var GRAVITY:Number = .5;
var ball:MovieClip = returnBall();
this.onEnterFrame = run;

function distance( dx:Number, dy:Number ) : Number {
   return Math.sqrt( dx * dx + dy * dy );
}

function offset( dist:Number ) : Number {
   return ( magnet_radius - dist ) * coefficient;
}

function project( dist:Number, dx:Number, dy:Number ) : Object {
   var theta:Number = Math.atan2( dy, dx );
   var magnitude:Number = offset( dist );
   return { x:Math.cos( theta ) * magnitude, y:Math.sin( theta ) * magnitude };
}

ball.vx = 0;
ball.vy = 0;

function run() : Void {
    var forceX:Number = 0;
    var forceY:Number = GRAVITY;
   
    var dx:Number = magnet._x - ball._x;
    var dy:Number = magnet._y - ball._y;   
    var dist:Number = distance( dx, dy );   
    if( dist < magnet_radius ) {
        var projection:Object = project( dist, dx, dy );       
        forceX -= projection.x;
        forceY -= projection.y;   
    }   
    ball.vx += forceX;
    ball.vy += forceY;   
    ball._x += ball.vx;
    ball._y += ball.vy;
}

function returnBall() : MovieClip {
   return ball;
}

This code applies gravity, inertia, and opposing magnetic force. A ball falls on a negative magnet and is moved by the force of the magnet. If i drop the ball directly over the magnet, the ball will come to a bouncing repetition when both forces balance.
I need a dynamic bounce. The idea something is hovering in place with a sort of a random bobble.

http://www.spiderarts.com/main.html

Here is an example of what i have so far so you can get a feel for what im goin for!

Basicaly it all comes down to -- Where do i put the Math.Random ?

Math.random()
Curious, anyone know of an impoved Math.random() function. I want a random function that is slightly more versatile. One that I could maybe specify a range of values to generate random numbers for... Anyone got any extended versions? Or should I sit down an hammer something out?

Math.random - How Can I Limit It Between 1 And 100 ?
I want flash to pick a number randomly - but the nr has to be between 1 and 100 --- HOW ??

I remember reading about this a while ago ... but it seems I've forgotten EVERYTHING ....

Math.Random Problems?
hi, I have a project I'm working on that I need to generate random questions for.

I opted to set each question up in its own .SWF file, then load them into the main movie randomly.

there are 10 questions I want users to answer, so when the go button is pressed, flash randomly displays a question between 1 and 10, after this has been answered it selects another between 1 and 10, until they have all been asked. Any ideas how to set this up????

also is it possible to 'record' how many of the questions a user got right, I thought maybe using variables, ie, "score = 0" then on each correct answer set a script to add 1 to the variable value at the end of 10 questions display the value of the variable name "score"

Help please......

Boxing Random Math ... Non The Same Ever ?...........? How Do I Do It
well i am doing a boxing game but i need a random math solutioon to see if it is a KO a win or a draw? any ideas?

it has to be different odds to or else it wouldnt work ... so anyideas?

Math.random Troubles
I'm using Flash 5 and I am just starting to try my own actionscript. I am trying to randomly pull up different movieclip symbols(which are parts of a dancing squirrel) so that the movie is not viewed the same everytime. I have gone about solving the problem like this....

I have set the seperate movieclips in different frames...2,3 and 4
In the first I want to actionscript out something like ...

if(Math.random(3)=1){gotoAndPlay ("2")}
if(Math.random(3)=2){gotoAndPlay ("3")}
if(Math.random(3)=3){gotoAndPlay ("4")}

This doesn't seem to work. What am i doing wrong? Any help would be glady appreciated. Thanx..
Oh yeah and check out the real dancing squirrel at http://www.locotopia.com

Ok With Math.random. What Am I Missing Now?
Allright, the thread about Math.random was because i'm trying to load 4 movies by using this:


Code:
variavel = Math.random() * 3;
if (Number(variavel) == 0) {
loadMovie("flash/orappa.swf", "discohold");
} else if (Number(variavel) == 1) {
loadMovie("flash/rappamundi.swf", "discohold");
} else if (Number(variavel) == 2) {
loadMovie("flash/ladobladoa.swf", "discohold");
} else if (Number(variavel) == 3) {
loadMovie("flash/instinto.swf", "discohold");
}

But it doesn't works... what should i do?

OK...got it...is working now. If you're a moderator you can delete this post.

AttachMovie..random...Math...help
Hi,

I need help in creating a grid of images 6*14 through actionscript. Each block in the grid consist of an image movieclip of the dimension 50*50 pixels. There is no gap between the blocks.

The catch is that a total of 84 different blocks, but I want to use only 28 image clips. Which means each block is to be repeated thrice. That's where I wanted to use random arrangement of the blocks.

All this is to be in a movie clip rather than in _root level. And is it possible to regenerate a new arrangement after a number of frames or by rerunning the script in another keyframe.

I have tried to achieve this for the past two days, using attachMovie and math but haven't succeeded. It compliments a similar grid using duplicateMovieClip commmand, but it is duplicating a single movieclip 84 times.

I understand that I'll have to create 28 clips and export for actionscript from library.

I'm using MX and am fairly started actionscript. Any help will be greatly appreciated

Shady
________________________________________________
[COLOR=sky blue]//my duplicateMovieClip script:[/color]
count = 0;
for (i=0; i<6; i++) {
for (x=0; x<12; x++) {
duplicateMovieClip ("frame", "frame"+count, count);
this["frame"+count]._x = x*50;
this["frame"+count]._y = i*50;
count++; }
}
_________________________________________________: confused:

Math.random() Question
Hi,

I am making a flashcard system using flash 5 for a chinese course i am doing. As you can see from the attached fla, I am breaking it up into lessons which shows each character in a linear way. This is easy to do but I would also like to have the choice of it choosing random entries from ALL the characters in ALL the lessons when it is finished.

by the time i am finished there will be hundreds of characters. i first tried giving every character (there are only 36 atm) a frame label from 1 - 36 & used math.random()*35)+1 to choose a random number between 1 & 36. however, i wasn't able to get my code to go to any of the frame labels except for frame label 1 & 0 (which shouldn't even get chosen).

so, since every character on the timeline is located on a frame number that is always a multiple of 5 plus 1 (6, 11, 16, 21..... to 186), i used Math.ceil (Math.random ()*37)*5+1, which should generate a whole number between 1 - 37, multiply it by 5 then add 1.

i am not sure if this is correct (i have never been good at maths) but it appears to be working the way i would like. can anyone tell me if my approach is correct & also whether this code will give me ALL the available frame numbers on which each of the characters sit.


cheers polly

Math.random Question
can someone please explain to me math.random? I've looked it up in the help and appear to be let down by my mathematical incompetence!

for example how would I get the following

a random number from
0 to 100?
90 to 100?
-100 to 100?
-100 to -50 AND 50 to 100? (i.e. not including -49 to 49)

if someone could explain the feature i'd be very grateful or if someone could just show me the code for the above I think I could probably work it out.

Cheers

Math.random Question
I have 9 numbers, and I want them to be put in a random order.

I have {1,2,3,4,5,6,7,8,9}
An example after randomizing {3,7,1,2,9,8,6,4,5}

I've tried a bunch of different ways but it's harder than I thought. Any suggestions?

Math.random HEEELP
This is weird..

on (release) {
myVar = Math.round (Math.random ()*13+1);
}

I get a number called 0 ! And that is not a number in blackjack lol!

What could i be doing wrong?

Question About Math.random
Ok, this script makes Flash advance to a random frame within a certain spectrum:
code: gotoAndStop(Math.round(Math.random()*2)+4);
Is there a way to tell Flash to choose between specific framelabels? (eg.: "one", "two", "three", "start")
Thanks for your help!

Safari And Math.random
Has anyone experienced problems with generating random numbers (using math.random) on Safari browsers? Upon starting the swf on Safari they seem to generate the same 'random' number, while on other browsers math.random works like it should, so I'm told.

Getting The Right Math.random Number
Hi guys

I am trying to generate a number using math random

based on there being 360 degrees i need a number between 300 deg and 60 deg

Or plus 60 and minus 60?

Using papervision and need to randomly tilt the object randomly on the y axis between those 2 numbers.

Here is what i have at the moment


PHP Code:



rotationY:Math.random() * 60 - 60,




Please help!

Math.random Weights (more/less Likely)
using math.random is it possible to set the likelihood of the same integer occurring.
i am using Math.floor(Math.random()*4)

but i want it to be unlinkely to go 1,2,2,2,3,1,4
instead i want it to go 3,4,2,1,3,2
for example!

thanks
Dan

[CS3] Why Is Math.random() Always Generating 0?
Here's my code, in a .as file. I'm trying to put some enemies on the stage and have them each be assigned a random speed and direction. I know the code isn't done (for instance, they would just go off the stage now instead of bouncing), but the trace() statement I have always returns 0 for some reason. If I replace the Math.random statement with some literal number, they will all move in that direction. (I actually want each enemy to have a unique direction, but that's another issue!)

Thanks for any help...I'm pretty sure it must be a very simple newbie oversight.


Code:
package {

import flash.display.MovieClip;
import flash.events.*;

public class Keepaway extends MovieClip {

public var numEnemies:int = 5; //this is the number of enemies
public var enemyX:int = stage.stageWidth/2; // where enemies start
public var enemyY:int = stage.stageHeight/2; // where enemies start
public var randomX:int; //to set enemy direction
public var randomY;int; //to set enemy direction


public function Keepaway() {

//cover the stage with a background rectangle of the same size
var theBackground:Background = new Background;
theBackground.width = stage.stageWidth;
theBackground.height = stage.stageHeight;
addChild(theBackground);

//add some Enemy symbols and give them random sizes and directions
//have them bounce if they hit the sides of the stage
for (var i:int = 0; i < numEnemies; i++) {

var enemy:MovieClip = new Enemy;
enemy.x = enemyX;
enemy.y = enemyY;
enemy.scaleX = 1 + i/5; // make each enemy a little larger
enemy.scaleY = 1 + i/5; // make each enemy a little larger
randomX = Math.random();
randomY = Math.random();

trace(randomX); //this is always 0!!?

enemy.addEventListener(Event.ENTER_FRAME, moveEnemy, false, 0, true)
addChildAt(enemy, 1);
}

function moveEnemy(evt:Event){ //give each enemy a random motion and bounce if they hit the edge of the stage
var myX:int = randomX;
var myY:int = randomY;
evt.target.x += myX * 5;
evt.target.y += myY * 5;

}
}
}
}

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