Codes and programs

This page contains codes and little programs I’ve made

Random numbers



How long would it take to make a coin land on heads 10 times in a row?

Let’s say 1 is heads, and 2 is tails. And let’s say that one toss takes 7 seconds.

This program uses the secsToDHM function.

heads = 0; tosses = 0
while(heads < 10):
	toss = Random.randint(1,2)

	if toss == 1:
		heads += 1
	else:
		heads = 0

	tosses += 1


print(f"It took {tosses} tosses ({secsToDHM(7 * tosses)})")


# How many spins does it take on a roulette wheel to hit zero X times in a row?
# We'll go with 30 seconds per spin for this one
spins = 0; green = 0
while(green < 4):
	spins += 1
	spin = Random.randint(1,37) # 37 is green

	if spin == 37: green += 1
	else: green = 0

print(f"It took {spins} spins to hit green 4 times in a row ({secsToDHM(30 * spins)})")

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *