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




Sorted Numbers..random



Hi there,

I created a MC in which we get 6 numbers out of 49..randomly..as in LOTTARY,,,,
But I want my numbers listed (sorted) first the small ones then the bigger ones.(4<14<22<33....)..I want both of them...ordered(second line.).and let the same numbers be disordered(first line)..as when they first appeared)"see my mc at"http://sabitgencoglu.tripod.com" (12)
How can I do this?

Thanks



FlashKit > Flash Help > Flash Newbies
Posted on: 02-05-2003, 01:36 PM


View Complete Forum Thread with Replies

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

Sorted Arrays Not Tracing Sorted?
when pasting the following code into a blank fla's frame one and testing it by putting a button on main stage that runs getAllBooks, why does the array at the end of the code not trace sorted? what's wrong with my set-up and or the function sortBooks?


ActionScript Code:
function shuffle() {
    return Math.floor(Math.random()*2);
}
function sortBooks(a:Number, b:Number):Number {
    if (a<b) {
        // book 'a' is lower then book 'b'.
        return (-1);
    } else if (a>b) {
        // book 'a' is greater then book 'b'.
        return (1);
    }
    // book 'a' equals book 'b'.                   
    return (0);
}
function getAllBooks() {
    //introduce all the book slots
    FTR = [];
    P1FC = [];
    P1SC = [];
    P1H = [];
    book = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
    book.sort(shuffle);
    //get all the books
    FTR.push(book.pop());
    FTR.push(book.pop());
    FTR.push(book.pop());
    FTR.push(book.pop());
    FTR.push(book.pop());
    //trace books in FTR array
    trace(FTR);
    //push next two books into P1FC and P1SC arrays respectively
    P1FC.push(book.pop());
    P1SC.push(book.pop());
    //push contents of FTR, P1FC, and P1SC arrays respectively into P1H array
    P1H.push(FTR);
    P1H.push(P1FC);
    P1H.push(P1SC);
    //make sure all the books are in the array
    trace(P1H);
    P1H.sort(sortBooks);
    //make sure P1H array is sorted
    trace(P1H);
    //this won't even work either
    P1H.sort(Array.NUMERIC);
    trace(P1H);
}
stop();

Random Function & Unique Random Numbers
Hello, after some searching i can't seem to find any good explanation to how and why i should use the Math.random() function so maybe i should explain how a function i need should work and someone maybe has some ideas.

I'm making a guessing program where you guess the right answer.

The function i have now randomly selects a number from 0 to 5 and then put's these five numbers into an array, the thing is that i need the numbers to be unique and i have no idea on how to make this.

Another thing i need to do is between these numbers that the random() function gets one is to be removed and instead i put the right answer there so now i also need one of the randomizes numbers to not be the right answer.

Also, how should a Math.random() function call look like so i can edit the range of numbers to randomize from?

Random Numbers
Hi, I'm trying to make a dynamic text box display a string of 4 or 5 numbers that rapidly change at random. I'm beginning to think that a text box may not be the way to accomplish this, but I'm at a loss. I've referenced my books, and the FLA's here on Flashkit, but just can't seem to find quite what I'm looking for. Any ideas? Thanks a lot for the help.

REALLY Random Numbers?
I have created a flash movie which creates a random number (eg 1-370) and then getsurl from a dynamic asp page based on that number. The result is a random tagline.

I hava noticed, however, that the taglines don't seem to be very random. Some of them are very frequently repeated while others are seldom seen.

Maybe it's just my idea but on the other hand maybe the random() function just doesn't work so well.

What do you think?

Is there a way to create randomer (!!!) numbers?

(I have though of getting a random number directly from the asp - visual basic script but I think this would be a waste of server resources)

Random Numbers
I was wondering if anyone knew of an Actionscript code that woudld randomly generate a number between 0-9 and continually loop. There would be a string of like 8 numbers that would continually change like I stated above? If you know of any tutorials that do this I would appreciate the link or site that has it. Thanks in advance! TC

Random Numbers ?
when using the random command is it possible to define where the random number starts . So it could be like
random (50-100); or would i have to put a check of sorts .

if (random>=49) {
gotoandplay ("sameframe");
}
else {
gotoandplay ("nextframe");
}

Random Numbers
How can you make flash choose a random number from a set? Such as {5, 10, 15, 20} or {-3, 0, 2, 13}

Also, how can you make random() generate negative and positive numbers?

DIFFERENT Random Numbers
I have a slot machine game, i need to make the slots stop at different icons. I use Math.random to go to different one son each slot. The problem is they always go to the same one. Can you try fix it, heres the .fla:
http://xtraterrestrial.orcon.net.nz/slotmachines.fla

Random Numbers
I'm working on a new project, where I have MC's coming down from the top of the screen...and I had them on Paths. But I didn't like how all of the animations were all the same, and it was predictable where the MC's were going to go. So I decided to write some code, and I decided to add a random number for each _y move of the MC. I added 'random (3) because I would add a number between 0 and 2 to the _y value of the MC. But I needed to also add negative numbers so that the MC would move back.

I need to know how I can get random numbers from the margin of -3 to +3. If anyone can post a reply that would be very helpful...thanks...

Random Numbers
Can somebody please help me out w/ random numbers. I'm trying to write a script that produces 8 different random numbers between 1 and 8. I need it not to produce duplicate numbers. Please help! I'm using Flash MX in case that matters.

-Nik-

Random Numbers?
Any of you guys play any game with HP (hitpoints) and when u get hit you lose hp... For this, I want to make a HP for a character and when it subtracts it goes a random number between 2 numbers... for example if its 1 - 10 the random number has to be between those... is this possible?

Random Numbers
What is the difference between
math.round(math.random(10)); and random(10); ??

I saw someone use the first option in a tutorial but didn't get the point..

Plz Help (random Numbers)
im tring to get txt boxes to generate random numbers without repeating a random number ive attached a file that should give you a better idea of what i mean

Random Numbers
I don't know where to post this really, but this forum sounds good.

I want to make little thing where you push a button and it gives a random number, from 1 to 99999999, it's for an experiment sorta. I'm using Flash 4. I'm pretty new to flash, so explain as best you can please.

Random Numbers
I'm trying to get a random number between -350 to 350. random() only gets number from 1 to 350. Is there anyway to get a negative and positive random number?

Random Between Two Numbers
Hi there!

I need to get a random number between two numbers. For example, to get an integer number between 10 and -10.

How can I do it?

Regards!

Random Numbers
Hello,

Is it possible to select random numbers? I am trying to select three different .jpgs that are numbered 1 - 12. Any help would be great!

Thanks,
DigitalMac

Random Numbers
Hey Forum,

I have created six text boxes on my program and I have got six random numbers being displayed out to them. The problem is that every now and again I get two of more of the boxes with the same number in them.

Could someone help me I want to get six unique numbers being displayed out isnt here is what i have any ideas. Still quite new to this.

random1 = random(49)+1;
random2 = random(49)+1;
random3 = random(49)+1;
random4 = random(49)+1;
random5 = random(49)+1;
random6 = random(49)+1;

Random Numbers
how to pick out 5 random different numbers from 22 numbers?

Random Numbers?
How do I make a random number that corresponds to the frame I want to go to?(I'm using Flash MX)

Random Numbers?
I have this to load a random pic from a folder. I have named the pics 1-57
this script look in the folder, makes a random number from 1 to 57 then adds the
.jpg to it then loads it in a movie I named picholder.

the problem is with the random number is if I where to have say two pic holders each with picholder1.loadMovie(Math.round(Math.random()*57)+ ".jpg");

I tend to still get the same number generated. So I thought I would and a number in to the generated number of the second random number so I would have something like this


picholder1.loadMovie(Math.round(Math.random()*57)+ ".jpg");
picholder2.loadMovie(Math.round(Math.random + 1()*56)+".jpg");

that way if they both get the same number (say 24) then picholder 2 would and a 1 to the number it loads making it a 25 so the output would be

picholder 24.jpg
picholder 25.jpg

the thing is I don't know ho to get that to work. any help?

Random Numbers
Hi,

I want to generate 3 numbers between 35 and 95 and would like the numbers to be at least 10 apart. For example: 38, 49, and 65. I'm using the following code to make sure the numbers are different but how do I alter it for the second constraint?

num1 = Math.floor(Math.random() * 61 + 35);
num2 = Math.floor(Math.random() * 61 + 35);
num3 = Math.floor(Math.random() * 61 + 35);
while (this.num1 == this.num2 || this.num1 == this.num3 || this.num2 == this.num3) {
num1 = Math.floor(Math.random() * 61 + 35);
num2 = Math.floor(Math.random() * 61 + 35);
num3 = Math.floor(Math.random() * 61 + 35);
}

Thanks a lot!

Random Numbers
Hello,
I have a random numbers text effect that I'm trying to accomplish with AS.
I have successfully created it on the timeline with by jumping to a new frame, but I have so many to do that wouldn't be time efficient.
-
Here's a link of what I mean:
http://www.micelistudios.com/random
-
The top red text is done with AS, BUT the problem is that I want the text letter spacing to be tighter, it seems only possible with one text box and this is done with a series of text boxes. The bottom grey text effect is what I want to achieve but with AS - DOES ANYONE KNOW HOW I CAN CONTROL THE LETTER SPACING AND ACHIEVE THIS EFFECT WITH AS AND USE A SINGLE TEXT BOX FOR THE ENTIRE SENTENCE ?

Random Numbers
I was wondering if there was an easier way to select a random number between:

-10 and 5 & 5-10

like choose one of these:

-10,-9,-8,-7,-6,-5,5,6,7,8,9,10

I know an easy was would be:

upordown = random number between 1 and 2

if(upordown ==1){
make random number between -10 and -5}
else{make number between 5 and 10}



Just wondering


Thanks!

Random Numbers
my mom is a teacher. i'm trying to make her a game to test her 3rd graders multiplication facts. i've got a timer set for two minutes, and in the two minutes they are supposed to answer some multiplicaition questions.



here's what i need help with.... i need TWO random numbers (1 through 12) to appear on the stage. (they CAN repeat)

**there needs to be a way the computer will check to see what the two numbers multiplied together would equal, to see if the students answers are correct. **




i'm a blonde, and still somewhat new on coding in flash... so explain things to me please! thanks!

Emily Pauline Davis

[F8] Random Numbers
Im trying to get about 6 numbers to generate randomly. e.g. 128963 to be displayed on a text box. Anybody know how to do it? Here is my code so far:

Code:
var RNDnumber:Number = 10000 +Math.floor(Math.random()*90000)


I dont know what to do with it??

[CS3] How Do I Random Between 2 Numbers?
So say I want a number randomly generated between x and y how do I go about this.

Random Numbers
Fixed again =S

[CS3] Random Numbers (help)
I have 5 variables. I want each variable to be a different number 1-5 onClipEvent(load){. How can I do this? I tried using a big If((not…){ }else{
code and var nums = [1, 2, 3, 4, 5];
for (var i in nums) {
nums[i] = nums.splice(Math.floor(Math.random()*nums.length), 1, nums[i]);
}
trace(nums);
var num1 = nums[0];
var num2 = nums[1];
var num3 = nums[2];
var num4 = nums[3];
var num5 = nums[4];
//
trace(num1+" "+num2+" "+num3+" "+num4+" "+num5);

None of them work. Any other way to get a different, random number for each variable? help PLEASE!

AS3:Random Numbers
how do you get a number between say, 15 and 20 in AS3

Random Numbers
Hi, i'm relitively new to action script but have a good understanding of it and have recently been trying to make a simple game, for the hell of it, and i want to know how you can generate a random number. What i'd like is a random number between -x and +x of x (e.g. -5 and +5 of 10) and it'd need to work when the 10 became an 11 for example....
Any help on this would be greatly appriciated.
Thanks,
Abi. Xx

Random Numbers
Hello!

I need to select 8 random numbers from 50. Anyone know how I can do this without getting duplicates? And preferable without dividing 50 into 8 blocks and randomly getting numbers from them!

Cheers, PV

Random Numbers
Hi,

How to generate the non repeating random numbers?

Please help to solve this.

Regards
Suresh

Random Numbers
i am using a random number action and it don't seem to spread the numbers out is there a way to make the number more spread out.


ActionScript Code:
onClipEvent (enterFrame) {
    if (_root.Boddy._x <= xtarget + 5 || _root.Boddy._y <= ytarget + 5){
        xtarget=Math.ceil(Math.random()*750)+50;
        ytarget=Math.ceil(Math.random()*650)+50;
        xstart=_root.Boddy._x;
        ystart=_root.Boddy._y;

    }
}

[help]not So Random Numbers...
Hi: i was sure that there was a tutorial here (besides this one) about how to get not so random numbers (like, get random values but not the same more than two times in a row) but can't find it anymore . Does anybody knows how to do it? or where's the tutorial now?

Thanks in advance

Sir Patroclo

Random Numbers
I am having difficulty creating a function that will randomize a number out of 20, the goal is I don't want it to repeat any of the previous numbers that have been assigned to the variable.

For example, if I have myRandomNumber as my variable and I run the function it will pick a random number out of 20 but when I run the function again I'm having a problem with the numbers repeating.

Is there anyway to eliminate the repeating?

4 Different Random Numbers
Hey.

I have a problem.
I want to make some kind of lotto number generator. Possible numbers from 1-20 and script has to choose 4 of them and show them in dynamic text field. This 4 numbers must be different numbers.
Any idea how to do this?

Well... Actually the only problem is with 4 different numbers.

Thanks for you help in advance

Regards
Corey Steel

[FMX] Random Numbers
hi, i'm generating two random numbers, between 1 and 4, which must be different to each other each the two numbers are picked. i've tried the following: var firstRandom = Math.random()*3+1;
var secondRandom = Math.random()*3+1;
var boxA = "box"+(Math.round(firstRandom));
var boxB = "box"+(Math.round(secondRandom));
if (firstRandom == secondRandom) {
var secondRandom = Math.random()*3+1;
var boxB = "box"+(Math.round(secondRandom));
} else...

and i still get two numbers the same occasionally. why isn't it comparing the numbers? is there a better way to achieve this? thanks in advance.

Random Numbers?
How can I make random numbers come on a slide?
like wen u clikc on a button i want a random number of 1,2,3
how can i do tat?

plz help its for my homewrk

Random Numbers Help Please
Hello.

I want to return a random whole integer between 0 and 4 for a 1:5 ratio of returning one of these numbers.

I currently use Math.round(Math.random()*4; Since flash will round the result, 0-3 will occur more often because the can be rounded to from a higher or lower number, while 4 can only be rounded up too... Does that make sense?

So, how do i get an even ratio of 1:5?

Help With Random Numbers
Hey everyone!

Im kinda new to flash, however I am making a game, and heres the 1st boundary in my way:random numbers

I was looking at the actionscript dictionary, looked it up on kirupa.com but i couldnt really figure it out.
Could someone plz help?

What Im trying to do is generating 2 random numbers within ranges of X (220-480) and Y (70-330). Im going to be using these for new location of an MC.

Thanks in advance!

PS.:There is another 1, but i dont wanna mix them all up in 1 thread.Thx for understanding!

Random Numbers
Hello all...

I need to be able to select a random number between 1 and 200... however, I don't want the number to be selected more than once...

I found this code:


HTML Code:
var minNum:Number = 1;
var maxNum:Number = 200;
var numbers:Array = new Array();
var count:Number = 0;
for (i=minNum; i<=maxNum; i++) {
numbers[i-1] = i;
}
numbers.sort(shuffle);
this.onMouseDown = function():Void {
trace(getNum());
};
function shuffle():Number {
return Math.floor(Math.random()*3)-1;
}
function getNum():Number {
if (numbers[count] == numbers[numbers.length-1]) {
numbers.sort(shuffle);
count = 0;
}
return numbers[count++];
}
However, this returns a whole array rather a single number.

How do I get at the first number in this array?

I am making a quiz game and want to return a random number (number) which displays a question using an 'if' statement: if number == 1{ etc.

I don't want the same question to be displayed for the remainder of the game.

I hope that this all makes sense...

Cheers for any help...

David

Random Numbers
this seems simple, but i am having a hard time doing this. For a class in school i am making a game similar to supermarket sweep. Incase you haven't seen the show: in order to gain time for shopping you must answer 10 trivia questions at the beginning, but... I DONT WANT ALL OF THE QUESTIONS THE SAME!

*i would like 20 questions to choose from
*i only want 10 questions to show up
*each question different (*no repeats*)
*after the 10th i would like to go on with the rest of the game

~~ i would love anyone even w/sugguestions! and hey.. thanks for reading this! SORRY SO LONG emily

[FMX] Random Numbers
hi, i'm generating two random numbers, between 1 and 4, which must be different to each other each the two numbers are picked. i've tried the following: var firstRandom = Math.random()*3+1;
var secondRandom = Math.random()*3+1;
var boxA = "box"+(Math.round(firstRandom));
var boxB = "box"+(Math.round(secondRandom));
if (firstRandom == secondRandom) {
var secondRandom = Math.random()*3+1;
var boxB = "box"+(Math.round(secondRandom));
} else...

and i still get two numbers the same occasionally. why isn't it comparing the numbers? is there a better way to achieve this? thanks in advance.

Random Numbers?
How can I make random numbers come on a slide?
like wen u clikc on a button i want a random number of 1,2,3
how can i do tat?

plz help its for my homewrk

Random Numbers Help Please
Hello.

I want to return a random whole integer between 0 and 4 for a 1:5 ratio of returning one of these numbers.

I currently use Math.round(Math.random()*4; Since flash will round the result, 0-3 will occur more often because the can be rounded to from a higher or lower number, while 4 can only be rounded up too... Does that make sense?

So, how do i get an even ratio of 1:5?

Random Numbers
I want a text field that randomly generates a number either 1 or 0.

Code:
onClipEvent (enterFrame) {
shuffle = random(2);
}
I tried this actionscript, but if u duplicate the text area (lke i want to do) each text area shows the same number at the same time even though its supposed to be random. HELP!

Help: Random Between Two Numbers
How i make a random between two numbers?

Ex.:

Math.random(100) --> the result will be between 0..99

but i need for example a result between 250..300.

How i do that??

Thanks in advance

Paulo

Random Numbers
Say I want to generate a random number between 1 and 50. Is there a difference between this:
Code:

Math.round(Math.random()*49)+1
And this:
Code:

random(51)
?

In testing them, I found that they seem to yield the same results, but I was wondering if there is in fact a reason to use one over the other.

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