简体   繁体   中英

making kbc using flash action script

i'm working flash action script .i'm generate random question
can u help me for generate sequential question for doc file.

 i = 0;
    randno = Math.randomInt(totques);
    if (counter==1) {
        randno = Math.randomInt(totques);
        quesover = new Array;
        quesover[1] = randno;
    }
    else {
        for (i=0; i<counter; i++) {
            if (quesover[i]==randno) {
                randno = Math.randomInt(totques);
                i = 0;
            }
        }
        quesover[counter] = randno;
    }
var myQues:Array = ["Q1", "Q2", "Q3", "Q4", "Q5", "Q6", "Q7", "Q8", "Q9", "Q10"];
var randomQues:Array = [];
var randomCount:Number =1;
var r:Number;
for (var i = 0; i<randomCount; i++) {
r = Math.floor(Math.random()*myQues.length);
randomQues[randomQues.length] = myQues.splice(r, 1);
}
trace(randomQues);

This is a variation of the Fisher-Yates algorithm (as is the other solution) but it should be a lot faster and it shuffles in-place instead of creating a new Array.

var source : Array = ["Q1", "Q2", "Q3", "Q4", "Q5", "Q6", "Q7", "Q8", "Q9", "Q10"];
var temp : String;
var index : int;
for( i = source.length -1 ; i > 0 ; i-- ){
    index = Math.round( Math.random() * i );
    temp = source[ i ];  
    source[ i ] = source[ index ];
    source[ index ] = temp
}
i = 0;
    randno = counter;
    if (counter==1) {
        quesover = new Array;
        quesover[1] = randno;
    }
    else
    {
        quesover[counter] = randno;
    }

This answer is my question

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM