Hello there!
I’m generating some random numbers and I’m putting them inside an array. How do I go about so no number repeats itself?
I have an array with the random generated numbers, which first i’m sorting.
If it find two numbers which are the same, it randomly generates the second number.
The result is then inserted into another vector.
function PozitiiRandom()
{
oldarrPositions = new Array();
newarrPositions = new Array();
var r:System.Random = new System.Random();
for(var j:int=0;j<pozitii.length;j++)
{
var k:int =r.Next(pozitii.length);
oldarrPositions.Push(k);
}
oldarrPositions.Sort();
//print("OldArrayLength="+oldarrPositions.length);
var m:int=0;
for (var i:int=0;i<oldarrPositions.length;i++)
{
oldarrPositions.Sort();
print("OldArray="+oldarrPositions);
while ((i>0) (oldarrPositions[i] == oldarrPositions[i-1]))
{
oldarrPositions[i] = r.Next(oldarrPositions.length);
// newarrPositions.Splice(i,1,oldarrPositions[i]);
// m--;
// newarrPositions.Push(oldarrPositions[i]);
//m++;
}
newarrPositions[m]=oldarrPositions[i];
m++;
}