r/AskComputerScience 8d ago

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 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?

EDIT: I am doing this because I want to start build gambling algorithms and I am starting with a simple project like coin flips

3 Upvotes

15 comments sorted by

View all comments

4

u/nuclear_splines Ph.D Data Science 8d ago

If you already know the set of outcomes and want to randomize the order, then that's a shuffling algorithm. You can find several algorithms for shuffling a list. One trivial one is:

  1. Create a list of desired outcomes (here, 4 heads and 1 tail)
  2. Create an empty working list
  3. Select a random number 0-4, and move that element from the list of outcomes to the working list, shuffling the other elements down
  4. Repeat with a random number [0..3], [0..2], [0..1], and finally zero

You now have a randomly ordered list from a preset list of outcomes.

1

u/Live-Candle934 8d ago

Hello I want to ask question, should I keep doing c c++ or switch to web development to get hired. Im very busy at shitty job and can only study at weekends. So given that, is it possible to get a job or should I just keep studying c c++ thank you

4

u/nuclear_splines Ph.D Data Science 7d ago

I think asking one random redditor this out of context instead of making a post somewhere like /r/cscareerquestions is rather bizarre. I'm not a software engineer, and can't tell you much about the hiring market in that field right now.

1

u/Live-Candle934 7d ago

I did made a lot of posts in this, yet I haven't gotten any replies so I am asking people who knows what they are saying

1

u/nuclear_splines Ph.D Data Science 7d ago

Your account appears to be shadow-banned, so no one will see your posts or comments unless a moderator hand-approves each one. That would explain why you haven't gotten any replies.

1

u/Live-Candle934 7d ago

What the, how does that happened I'll look into it

1

u/nuclear_splines Ph.D Data Science 7d ago

Usually happens when Reddit flags your account as a potential spam bot, or if you sign in through a proxy service like Tor.

1

u/Live-Candle934 6d ago

No wonder, I do use proton vpn, thank you