go to http://www.flashguru.co.uk/tutorials/arrays.htm
to get a introduction to arrays
Printable View
go to http://www.flashguru.co.uk/tutorials/arrays.htm
to get a introduction to arrays
thanks once again
Thanks all for the help with randomizing the array, thanks especially LuxFX and Dickee for the good examples.
-Hythian
HowardTheDuck
Sorry, after I had posted and shut down last night, I thought about my testing for octal, and recalled that I was testing in reverse (25/10 to 21/8), instead of how your sig actually displays (31/8 to 25/10) ... thanks for not flaming me too much! :D
Fleep2010
If you're dealing with a range of numbers, you can forego using arrays for the random, but if you're trying to randomize a list of string literals, then you must create an array to call the number of the string in the array for use with random. Here's a thread with more information on random for a series of numbers:
http://www.were-here.com/forums/show...004#post339004
http://members.home.net/stringedinst...azo-Random.swf
http://members.home.net/stringedinst...azo-Random.fla
LuxFX
Well, I've been exploring the speed of the 2 random functions, and your pop function wins, hands down! This makes sense, because pop doesn't need to search the entire array as does my splice function.
Each test is iterated 100 times, with a test mode trace of 100 lines, and a display field onscreen of the 100th iteration (just to show that random exclusive is achieved with each function).
However, I'm getting varying results ... Test Timer 4, my splice function, displays a mean time online of approximately 6285 milliseconds, but in test mode with all 100 traces displayed, I get a whopping 7800 milliseconds mean time (I just received the '15 seconds, I'm too slow' message at the 30th test offline, although I was also taxing the cpu with another window open at the time).
Test Timer 5, your pop function, displays approximately 1580 milliseconds online, and in test mode returns approximately 1890 milliseconds mean time. I imagine that this extra time offline is due to either the trace output of 100 lines, or the fact that test mode uses the 5.0.30.0 player, and online uses 5.0.42.0, or a combination of both reasons.
I made the timer.fla so that different functions can be pasted in for general testing purposes:
http://members.home.net/stringedinst...sh5/timer4.swf
http://members.home.net/stringedinst...sh5/timer4.fla
http://members.home.net/stringedinst...sh5/timer5.swf
http://members.home.net/stringedinst...sh5/timer5.fla
Summary for comparison to your results ... please post them:
AMD Athlon 550, 96 mb ram, Win98SE, IE 5.5
Test Timer 4: online - 6285, offline - 7800
Test Timer 5: online - 1575, offline - 1890
More Fodder for Father
FUNEM?
SVFM.
FUNEX?
SVFX.
LFMNX!
:D
Richard
[Edited by Dickee on 05-09-2001 at 04:18 PM]
Dickee
np man... it took a long time for me to figure out what you tried to do in your first post ;) Anyway it's cool that that many people even know what this joke means.
I don't think that Win98SE is a good CPU-time measure tool... I was a c++ developer in a company for professional vector grafics (banknotes and stuff...) and at first i had win98se running on my laptop - well development is a pain in the a$$ with this OS anyway (crashes, ...) - but when it comes to speed measurement it's definitely not useful. I had values differing up to 40% with the same surrounding conditions, so i had to switch to Win2k (which was not funny to get running on a Sony Vaio :()
Your tests show that there's a speed difference between the 2 codes, but it's just that each result can be totally wrong (too fast or slow). I maybe run these tests too on Win2k because it's interesting to see what flash does.
All the others
Wow, cool code examples around here...
yours, until the benchmarks are finished :)
HTD
Hey Howard, this is kind of off the subject, but I also have a VAIO, and I wanted to install Win 2K, but I've been too afraid. Any tips for not having to use their stupid Recovery Disks?
Oh man I tell you DON'T do it :)
you have to alter the BIOS because this is locked in old series to Win98se... Problem is that there are different bioses for US and Europe... you can crush your thing with this! plus there's NO more support for the notebook from sony (as if there would be some normally *cry*) after you changed to Win2k.
For some reason it worked for me though... Some driver issues and stuff came up but this is normal i think. I just did it because the company paid the notebook - if i had paid it i would have kept win98se running... Currently i have a newer one - they have win2k pre-installed...
Anyway here's a link from sony that should explain most stuff for migrating:
http://www.vaio-link.com/uk/kb/W2K304-305.html
Don't say i didn't warn you :D !
yours
HTD
Thanks! I'm glad for the warning, I really don't want to lose my baby!!! :)
prototype method:
:)Code:Array.prototype.shuffle=function(){
var o=this.slice()
var l=o.length
var n=new Array()
for(var i=0;i<l;++i){
var r=random(o.length)
n[n.length]=o[r]
o[r]=o[o.length-1]
o.pop()
}
return n
}
We have a new test leader! FlashGuru's prototype.shuffle tests even faster than LuxFX's randomArray.
After a count of 100 (1000 iterations) working on an array of 1-20:
LuxFX
Test Timer 5: online - 1838, offline - 1916
http://members.home.net/stringedinst...sh5/timer5.swf
http://members.home.net/stringedinst...sh5/timer5.fla
FlashGuru
Test Timer 5: online - 1370, offline - 1688
http://members.home.net/stringedinst...sh5/timer6.swf
http://members.home.net/stringedinst...sh5/timer6.fla
Way to go Guy!
Richard
[Edited by Dickee on 05-24-2001 at 01:19 PM]
Nice one:) he he..... good testing going on here dickee
Dickee, test this:
In my own testing in Flash's internal player, using your FLA, Flashguru's mean time was 1260 and mine was 720.Code://Robert Penner
Array.prototype.shuffle = function() {
var len = this.length;
for (var i=1; i <= len; i++) {
var randA = random(len);
var randB = random(len);
//swap random indices
var temp = this[randA];
this[randA] = this[randB];
this[randB] = temp;
}
}
myArray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
//note the function doesn't return a value--
//it just modifies the original array, like Array.sort()
myArray.shuffle();
PIII-700 256megs RAM
***THIS JUST IN***
I just tested
vs.Code:myArray = new Array (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
and my mean time dropped from 720 to 570. That's a 21% difference (for my code).Code:myArray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
Side note--Omit Trace Actions in the publish settings when testing in Flash; printing to the Output window slows it down.
Well, getting back to Hythian's original question on this thread, I've standardized the tests online by using F5's 'Math.random' for all 3 functions, rather than the proven-faster-but-deprecated 'random' method ... I've left the trace code in place, and I've included an offline result without trace for Robert's code just to compare it with the online result with the trace in place.
Robert's function is still the fastest, however, I'm not exactly sure of how it works to get the exclusive result ... I tried the function offline by deleting the 'b' random turn-around, and the return is an incrementing series 1-20. With that result in mind, when trying to follow the logic in the turn-around code, I can't see how the result randomizes (which it clearly does). Could you decipher the code logic for us Robert?
LuxFX:
http://members.home.net/stringedinst...sh5/timer5.swf
http://members.home.net/stringedinst...sh5/timer5.fla
FlashGuru:
http://members.home.net/stringedinst...sh5/timer6.swf
http://members.home.net/stringedinst...sh5/timer6.fla
RPenner:
http://members.home.net/stringedinst...sh5/timer7.swf
http://members.home.net/stringedinst...sh5/timer7.fla
Athlon 550, 96 mb ram, Win98SE:
Online tests: Math.floor(Math.random()*inc), using newArray = [] format, with trace in place.
RPenner - random(inc): []926, ()1117 ... Math.floor(Math.random()*inc): []1166, ()1347, with no trace[]897 ... online 1009
FlashGuru - random(inc): []1399, ()1689 ... Math.floor(Math.random()*inc): []1648, ()1839 ... online 1463
LuxFX - random(inc): []1696, ()1795 ... Math.floor(Math.random()*inc): []1746, ()1908 ... online 1690
On another note, I can't believe that there has been no comment on my 'fodder for father' ... particularly from LuxFX, whose very name holds the key to the encryption ... here's the skinny on it:
FUNEM? ... Have you any ham?
SVFM. ... Yes, we have ham.
FUNEX? ... Have you any eggs?
SVFX. ... Yes, we have eggs.
LFMNX! ... I'll have ham and eggs! :D
Richard
Hi...Finally work left some spare time for me to test this stuff too :-)
ok seems like WinME is much more reliable than i thought - i got nearly the same values as dickee with win2k (PIII 500), i know it's a bit late for that...
Looking at Roberts idea: it's basically the same as the one from LuxFX... just the coding is different.
to dickee... good job you've done here!!!
yours
HTD
Actually. LuxFX and FlashGuru's methods are the ones that are similar; there's almost a line-to-line correspondence. Here are all three for reference:Quote:
Originally posted by HowardTheDuck
Looking at Roberts idea: it's basically the same as the one from LuxFX... just the coding is different.
LuxFX
FlashGuruCode:function randomArray(arrayInput)
{
var temp = new Array();
var len = arrayInput.length;
for (z=0;z<len;z++)
{
var rndNum = Math.floor(Math.random()*arrayInput.length);
temp.push(arrayInput[rndNum]);
arrayInput[rndNum] = arrayInput[arrayInput.length-1];
arrayInput.pop();
}
return temp;
}
Robert PennerCode:Array.prototype.shuffle=function(){
var o=this.slice()
var l=o.length
var n=new Array()
for(var i=0;i<l;++i){
var r=random(o.length)
n[n.length]=o[r]
o[r]=o[o.length-1]
o.pop()
}
return n
}
Code:Array.prototype.shuffle = function() {
var len = this.length;
for (var i=1; i <= len; i++) {
var randA = random(len);
var randB = random(len);
//swap random indices
var temp = this[randA];
this[randA] = this[randB];
this[randB] = temp;
}
}
Hey Robert ... perhaps you skimmed over my message and missed this?
RichardQuote:
Robert's function is still the fastest, however, I'm not exactly sure of how it works to get the exclusive result ... I tried the function offline by deleting the 'b' random turn-around, and the return is an incrementing series 1-20. With that result in mind, when trying to follow the logic in the turn-around code, I can't see how the result randomizes (which it clearly does). Could you decipher the code logic for us Robert?
Right, I was going to reply but I had to leave for a meeting.
The last three lines are your classic "swap the values of two variables" using a third temporary storage variable.Code:Array.prototype.shuffle = function() {
var len = this.length;
for (var i=1; i <= len; i++) {
var randA = random(len);
var randB = random(len);
//swap random indices
var temp = this[randA];
this[randA] = this[randB];
this[randB] = temp;
}
}
The main concept is really simple; it literally is shuffling the array like you might shuffle cards in real life. Imagine putting 10 cards in a row on a table, then picking two at random and switching their places. If you do that 10 times, your cards are sufficiently shuffled. Make sense?
Yes, I realize that the turnaround shuffles 'the deck' ... but if you comment the turn-around and either randA or randB out of the function, it returns an ordered list 1,2,3,4,...20 ... shouldn't each individual random code generate a random list ... 5,9,14,2,...etc.? And how does the code not duplicate numbers in the shuffled list?
Richard