Hello,
I'm wondering how you can search an array for a certain value. I have declared my array:
int[] bl(4,20);
I want to then set each array to a random, unique value, like so:
for(int i = 0; i < 3; i++)
{
//set "bl[i]" to a random number between 0 and 7
bl[i] = RandInt(0, 7);
//if another value in the array is already set to this number, re-randomise until it is unique.
while(bl[i] == !!!Search array for the same value!!!)
{
bl[i] = RandInt(0, 7);
}
}
Any ideas what I need to put in to search my array?
Also, it would need to not include itself in the search (ie. if i = 2, it needs to ignore bl[2] in the search and only include bl[0], bl[1] and bl[3].
I see on the
AngelScript documentation it has "find(syntax)", but I'm unsure how to use it.
I have a kind of "hacky" solution. It works, but I'm sure there is a better way. I'll use this for now, unless anyone can come up with some cleaner code.
Also, copy and pasting code from Notepad++ loses its formatting on this forum...kinda annoying. >_>
for(int i = 0; i < 4; i++)
{
bl[i] = RandInt(0, 7);
if(i == 1)
{
while(bl[i] == bl[0])
{
bl[i] = RandInt(0, 7);
}
}
if(i == 2)
{
while(bl[i] == bl[0] || bl[i] == bl[1])
{
bl[i] = RandInt(0, 7);
}
}
if(i == 3)
{
while(bl[i] == bl[0] || bl[i] == bl[1] || bl[i] == bl[2])
{
bl[i] = RandInt(0, 7);
}
}
}