Whether we are developing a game or e-learning application we need to create random response which is unique and not repeating.

Say for example if you are developing a Quiz application where you have 10 questions, you want to pick the question randomly, but the same question should not be repeated.

Here is a custom class which we can use to produce such random values. I will write more about it in my next post

[UPDATE] included the ActionScript 3 version as well 🙂 It became lot more simpler with the regular expressions

/*
 ************************************************************
   Developed by R.Arul Kumaran [[email protected]]
   for more code keep visiting [www.luracast.com/all/blog]
 ************************************************************
 */
 /*
Coming Soon....
*/


 */
/*
/*
 ************************************************************
   Developed by R.Arul Kumaran [[email protected]]
   for more code keep visiting [www.luracast.com/all/blog]
 ************************************************************
 */

//custom class for producing unique random numbers
_global.randomResponse = function(a, b) {
        this.set(a, b);
};
//use the set method to set the random value
//to be an array or range of numbers
randomResponse.prototype.set = function(a, b) {
        if (a instanceof Array) {
                this.Arr = a;
        } else if (!(isNaN(a) && isNaN(b))) {
                this.Arr = [];
                var step = a