Member Avatar for olong tea

This questions contains probability and I dont know how to work with it in Java

import numpy 
import random 

def cup_game():

    cashprice = [0.5, 1.0 , 2.0 , 5.0]

    n_turn = numpy.random.randint(5,11)
    n_mult = numpy.random.randint(3,6)

    cups = list(range(0,15))
    x = numpy.random.choice(cashprice, 15, p=[0.3, 0.4, 0.2, 0.1])
    x = list(x)

    turn = ["t" for i in range(n_turn)]
    mult = ["m" for i in range(n_mult)]

    perks = turn + mult
    perk_assignment = random.sample(cups, n_turn + n_mult)

    perk_list = [0 for i in cups]
    for i in perk_assignment:
        perk_list[i] = perks[perk_assignment.index(i)]

    picks = 5
    multiplier = 1
    winnings = 0 
    total_picks = 0

    while picks > 0 and len(x)> 0:
        choice = x.pop()
        p = perk_list.pop()
        #print("cup:", choice, "perk:", p)
        if p == "m":
            multiplier += 1
        elif p == "t":
            picks += 1
        winnings += choice 
        picks -= 1
        total_picks +=1
        #print("winnings:", winnings, "multiplier:", multiplier, "picks:", picks, "total picks:", total_picks)

    jackpot = 0 
    if total_picks == 10:
        jackpot = 20
    elif total_picks == 11:
        jackpot = 50
    elif total_picks == 12:
        jackpot = 100
    elif total_picks == 13:
        jackpot = 200
    elif total_picks == 14:
        jackpot = 500
    elif total_picks == 15:
        jackpot = 1000
    else:
        jackpot = 0

    winnings = (winnings * multiplier) + jackpot
    return winnings
n = 10000
total = 0 
for i in range(n):
    total += cup_game()

print(total/n)

You’ll find what you need in Java’s Random class (Java.util.Random)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.