Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to shuffle colour balls?
- public IEnumerable<Color> GetColors()
- {
- int count = 400;
- // queue or another data structure to hold the last generated colors
- Queue<Color> lastColors = new Queue<Color>();
- var availableColor = new Dictionary<Color, int> {
- {Red, 100}, {Yellow, 40}, ...
- };
- Color nextColor = null;
- while(count > 0)
- {
- do {
- /* randomly pick from color buckets */
- nextColor = /* choose random color based on the weights*/;
- } while(/*it satisfies the condition, that it is not 3rd same color in a row*/)
- yield return nextColor;
- count--;
- }
- }
Add Comment
Please, Sign In to add comment