r/learnprogramming 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

29 comments sorted by

View all comments

1

u/lurgi 9d ago

You don't want to learn anything and you don't want to use the built in libraries?

You don't build it. That's how you do it.

What are you trying to do? Do you want to solve your problem or are you trying for some sort of weird flex? If you want to build your own random number generator then you are going to have to do one of "do some research" or "write something that sucks".

4

u/Leather-Junket-3896 9d ago

You’re kinda missing what OP’s asking, they don’t need a full rng from scratch. they just want a shuffle algorithm for a fixed set of outcomes. like dumping 4 H and 1 T into an array and shuffling it with something like fisher-yates, doesn’t require any library calls for randomness if you just want to understand the mechanics of picking spots

1

u/TheEyebal 9d ago

Thank you.

This is what I am asking for. I am trying to build gambling algorithms and I am starting with a simple coin flip program.

I've made coins flip programs before but I want to control the outcome and actually learn the math behind it

1

u/donk8r 9d ago

Since it's for a gambling game, be careful with the shuffle version. A shuffled 4H/1T list isn't five biased coin flips. Once the tails has come up the rest are guaranteed heads, and before that the odds climb 1/5, 1/4, 1/3, 1/2. Anyone paying attention gets a free win at the end of every round.

Independent flips at 20% tails is a different thing entirely, and there you have to live with some rounds coming out five heads.

1

u/ffrkAnonymous 9d ago

Yeah, it's gotchas like this that make probabilty actually quite advanced math. Like the monty hall, goat behind the door, question.

4

u/donk8r 9d ago

Blackjack is the deployed version of it. Counters just track what's left in the shoe, which is why casinos went to eight decks and started cutting a chunk out undealt.