I want to know logic over how to select six random numbers between 0 to 8 ,where if (0,1) or (1,2) or (0,2) got select then the remaining one number out of 0 to 2 shall not be selected again same goes for 3 to 5 series if (3,5) or (3,4) or (4,5) got selected then remaining one number shall not be selected.
So for example in series 0 to 8 six number can be (0,1,3,5,6,8) or (1,2,4,5,7,8) etc
To do this you need to track that over time. So some sort of collection will be needed.
Easiest route would be a List of the range of values. Randomly grab a value from the List, removing it in the process. When the list is empty, the sequence is complete.
//create sequence
var lst = new List<int>(9);
for(int i = 0; i < 9; i++)
{
lst.Add(i);
}
//extract value
int i = Random.Range(0, lst.Count);
int result = lst[i];
lst.RemoveAt(i);
Wow that seems to be new approach, This numbers are kind of spawn points, so if all 0-2 points get filled then path will be blocked for player to move ahead. How would I know and avoid with your way that 0 to 2 ( 3 to 5,6 to 8) all numbers has got generated?
Basically I don;t want to generate more than 2 number between 0 to 2 or 3 to 5 or 6 to 8 range.
so you want to guarantee a gap? simple, 3 ranges in a similar fashion as above. Randomly pick one from each range, as above. Don’t do anything with that number, just remove it.
Combine the three ranges and do as above to select the ones you want to use.
Sorry, I was wrong, there are 9 numbers (not 8).
So:
// Generate (0, 1, 2, 3, 4, 5, 6, 7, 8) list
List<int> result = Enumerable.Range(0, 9).ToList();
// Remove something in 0..2 range
result.RemoveAt(Random.Range(0, 2));
// Remove something in 3..5 range
result.RemoveAt(Random.Range(2, 4));
// Remove one more random value (now anything goes)
result.RemoveAt(Random.Range(0, result.Count));
This is problem that I would expect to see in Google Jam =D