using System.Collections.Generic;
public static void Main()
for (int i = 0; i < 500; ++i) {
string list = String.Join(",", _indexes);
Console.WriteLine(string.Format("After {0}: Match = {1}, Current = {2}, Array = {3}", i, MatchColorIndex, CurrentColorIndex, list));
GetRandomCabinetLightDataIndex();
public static int MatchColorIndex = -1;
public static int CurrentColorIndex = -1;
static readonly List<int> _indexes = new List<int>() { 0, 1, 2, 3, 4, 5, 6, };
static readonly Random _nativeRandom = new Random();
public static int GetRandomCabinetLightDataIndex()
if (MatchColorIndex >= 0 && MatchColorIndex != CurrentColorIndex) {
int randomNumber = _nativeRandom.Next(1, 100 + 1);
if (randomNumber <= currentOdds) {
UpdateOdds(MatchColorIndex);
if (CurrentColorIndex == -1 && MatchColorIndex == -1) {
index = _nativeRandom.Next(0, _indexes.Count);
} else if (MatchColorIndex == -1 || MatchColorIndex == CurrentColorIndex) {
MoveIndex(CurrentColorIndex, _indexes.Count - 1);
index = _nativeRandom.Next(0, _indexes.Count - 1);
MoveIndex(CurrentColorIndex, CurrentColorIndex);
MoveIndex(CurrentColorIndex, _indexes.Count - 1);
MoveIndex(MatchColorIndex, _indexes.Count - 2);
index = _nativeRandom.Next(0, _indexes.Count - 2);
MoveIndex(MatchColorIndex, MatchColorIndex);
MoveIndex(CurrentColorIndex, CurrentColorIndex);
static void MoveIndex(int indexToMove, int positionToMoveTo)
int indexOfIndex = _indexes.IndexOf(indexToMove);
int valueAtPosition = _indexes[positionToMoveTo];
_indexes[positionToMoveTo] = indexToMove;
_indexes[indexOfIndex] = valueAtPosition;
static void UpdateOdds(int index)
CurrentColorIndex = index;
if (MatchColorIndex == -1) {
MatchColorIndex = CurrentColorIndex;