actionscript 3 - Get unique random numbers from 1-40 -



actionscript 3 - Get unique random numbers from 1-40 -

i want unique random numbers each time nos 1-40 without using array.is there optimised way in action script 3.

no, have utilize permutation, have record numbers you've generated. , using these numbers require set of kind, aka array. it's possible solve issue using other info types, narrow downwards array of sort.

a simple permutation code looks this:

class permutation { private var _a:array; // or vector.<int> if private var n:int; // next element public function permutation() { reset(1); } public function reset(size:int=100):void { _a.length=0; (n=0;n<size;n++) _a.push(n); (n=0;n<size;n++) { var x:int=math.floor(size*math.random()); if (x==n) continue; var swap:int=_a[x]; _a[x]=_a[n]; _a[n]=swap; } n=0; } public function getnext():int { if (n==_a.length) homecoming -1; // or error value n++; homecoming _a[n-1]; } }

actionscript-3

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -