Guest User

Untitled

a guest
Aug 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. How to shuffle colour balls?
  2. public IEnumerable<Color> GetColors()
  3. {
  4. int count = 400;
  5. // queue or another data structure to hold the last generated colors
  6. Queue<Color> lastColors = new Queue<Color>();
  7. var availableColor = new Dictionary<Color, int> {
  8. {Red, 100}, {Yellow, 40}, ...
  9. };
  10. Color nextColor = null;
  11. while(count > 0)
  12. {
  13. do {
  14. /* randomly pick from color buckets */
  15. nextColor = /* choose random color based on the weights*/;
  16. } while(/*it satisfies the condition, that it is not 3rd same color in a row*/)
  17. yield return nextColor;
  18. count--;
  19. }
  20. }
Add Comment
Please, Sign In to add comment