Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate "characters" based on a probability

I need a little help with my tetris game that I am coding in C++ , here is my problem:

The list of tetris blocks are 7 types: {'I', 'J', 'L', 'S', 'Z', 'O', 'T'}

and i need to pick ONE of the above character such that S and Z are selected with probability 1/12 each, and the other blocks are selected with probability 1/6 each.

What is my best way to generate the blocks according to these probabilities?

like image 677
Shehryar Farooq Avatar asked Jan 29 '26 07:01

Shehryar Farooq


1 Answers

Declare and define a twelve-item array with a single occurrence of S and Z; two occurrences each of the rest; and pick a random element from that.

like image 193
Pontus Gagge Avatar answered Jan 30 '26 21:01

Pontus Gagge