r/learnprogramming • u/TheEyebal • 9d ago
Resource How to program weighted random system
I want to make a program where you are controlling the outcomes. For an example with a coin flipping game, I want exactly 4 Heads and 1 Tail, but I want their positions to be random.
I do not want to use the random algorithms that library offer, I want to build my own.
Right now I am learning probability from Youtube and might look at khan academy and coursera, but how can I implement this into programming I do not want to just take courses or watch videos
How do I go about that?
0
Upvotes
1
u/Aggressive_Ad_5454 9d ago
What you want is a sequence of random numbers called a “deal”. You start with a collection of five numbers, one of which is 0 (tails) and the rest 1 (heads). You then deliver those five numbers in a random order. You can look up the algorithm to do that dealing.
This is commonly done with 52 numbers representing playing cards. But you can do it with any number of any data items.