# Game using random frame feature

**URL:** <https://forum.kirupa.com/t/game-using-random-frame-feature/65021>\
**Category:** flash\
**Created:** [September 22, 2004, 9:27am UTC](https://forum.kirupa.com/t/game-using-random-frame-feature/65021 "2004-09-22T09:27:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gerb\_UK](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/gerb_uk/32/396_2.png) [@Gerb\_UK](https://forum.kirupa.com/u/Gerb_UK)\
**Post date:** [September 22, 2004, 9:27am UTC](https://forum.kirupa.com/t/game-using-random-frame-feature/65021/1 "2004-09-22T09:27:21Z")

</div>

Hi,

I’m building a game where on the press of a button a movie clip jumps to a random frame to display a question.

I know how to choose a random frame, but I need to be able to choose a random frame between two specific points, say from between frame 8 and 32.

Secondly, once a particular question has been chosen once, I don’t want it to be available to be chosen again until all of the other questions have been viewed - to stop repeated questions.

Any idea how I can do this – my actionscript is still a little basic 😊

Thanks…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 22, 2004, 11:28am UTC](https://forum.kirupa.com/t/game-using-random-frame-feature/65021/2 "2004-09-22T11:28:29Z")

</div>

Answered my own question:

In the actions layer create an array and shuffle it:

Array.prototype.shuffle = function() {  
var shuffledArray = [];  
var copyArray = this.slice(0);  
for (var j = 0; j\<this.length; j++) {  
randomNo = Math.floor(Math.random()\*copyArray.length);  
shuffledArray[j] = copyArray[randomNo];  
copyArray.splice(randomNo, 1);  
}  
return shuffledArray;  
};  
QuestionNumbers = [1,2,3,4,5,6,7,8,9,10];  
RandomQuestion = QuestionNumbers.shuffle();  
trace("RandomQuestion = "+RandomQuestion);

Then on the button to chose a question:

on (release) {  
if (RandomQuestion.length == 0) {  
RandomQuestion = QuestionNumbers.shuffle();  
trace(“RandomQuestion=”+RandomQuestion);  
capture = RandomQuestion.shift();  
trace(capture);  
} else {  
capture = RandomQuestion.shift();  
trace(capture);  
}  
}

This displays the first entry in the array and deletes it. If the array is empty, a new array is created. Random questions forever!

Hope this helps someone else…
