-
here's my problem: I need to choose 5 questions out of ten at random, the same question cannot come up twice in the serie of five,the questions are sitting on ten frames of a movieclip, 5 instances of that movieclip are on my page. effectively, I set up five random numbers wich will determinate on which frame each of my movie will stop.
I need to check for each random numbers if it is different of the other ones, otherwise i'll set a new random number.
For that, I set up a loop for each random numbers.
Goes like that to check, for example, the random number 4 agaist the others:
loop = 0;
Qnum = 5; //number of questions random numbers
while (loop <= Qnum) {
if (Number(RandomQ4) == Number(RandomQ add loop) and loop != 4) { //obviously Q4==Q4
RandomQ4 = RandomQ4 +1; // add one
prevFrame (); // go back and run the loop to check the new Q4
loop = loop +1;
}
}
I run this loop for every random numbers
I tryed with Number, with eval and without anything and nothing runs, any idea?
If you feel up for it, I can send you the fla...
my email: bastien.francois@eurorscg.co.uk
A pint if you crack it! (London)
cheers!
-
I had to solve a similar problem for a quiz myself, so here's a little cut'n'paste - hope it will help.
Anik =:)
------------------
aChiffresAleatoires = new Array(1);
for (x=0; x<10; x++) {
chiffre = Math.ceil(Math.random()*10-1);
for (y=0; y<aChiffresAleatoires.length; y++) {
if (chiffre == aChiffresAleatoires[y] && x<>y) {
x = x-1;
break;
} else {
aChiffresAleatoires[x] = chiffre;
}
}
}
---> in the end, my Array aChiffresAleatoires contains 9 different integers randomly generated, of 0-9 value. Do what you want with them :)
-
erh...., pretty clever but
-
Hey bastien!
I had a Lotto6_49 app on hand, so I modified it to just include pick and range for you.
Here's an example for you that you can choose up to 20 picks from an unlimited range:
http://members.shaw.ca/flashmath101/...usivePicks.swf
http://members.shaw.ca/flashmath101/...usivePicks.fla
Code:
frame 1
stop();
frame = 1;
picks = 5;
range = 10;
// Robert Penner - 2001 - exclusive-random shuffle
Array.prototype.shuffle = function() {
var len = this.length;
for (var j=0;j<len;j++) {
var rand = Math.floor(Math.random()*len);
//swap current index with a random one
var temp = this[j];
this[j] = this[rand];
this[rand] = temp;
}
}
// Richard Wright - 2001 - randExclusivePicks
// Dependent function exclusive_random shuffle
function randExclusivePicks() {
myArray.shuffle();
for (var j=1;j<=picks;j++) {
_root["pick"+j] = myArray.splice(0,1).toString();
}
}
frame 3
stop();
frame = 3;
// this generates a range of numbers for myArray
myArray = [];
for (j=1;j<=range;j++) {
myArray.push(j);
}
// for an array of questions, replace above code with:
/*
myArray = [
"question #1?",
"question #2?",
...
"question #n?"];
range = myArray.length-1;
*/
trace ("trace1: "+myArray);
randExclusivePicks();
trace ("trace2 - myArray after pick: "+myArray);
for (var j=1;j<=picks;j++) {
trace (eval("pick"+j));
}
Richard
[Edited by Dickee on 11-06-2001 at 02:56 AM]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|