Testing out Theoretic Probability

I got bored and wanted to test out probability vs theoretic probability. I created a roulette bot that minimum bets 1 dollar, but if it were to hit the same color X amount of times, it would bet on the other color but with a maximum bet - far more substantial than the minimum.

local color = 1
local lastColor = 0;
local amountColorHit = 0

local startingBalance = 1000000
local balance = startingBalance

local incrementUntilMaxBet = 9

local minBet = 10
local maxBet = 10000
local currentBet = minBet


for i = 1, 10000 do
	local colorPicked = math.random(1,2)
	if colorPicked == color then
		balance = balance + currentBet
	else
		balance = balance - currentBet
		if currentBet == maxBet then
			print('lost this one')
			continue;
		end
		if colorPicked == lastColor then
			amountColorHit = amountColorHit + 1
			if amountColorHit >= incrementUntilMaxBet then
				print('bet increased to max')
				currentBet = maxBet
				color = color == 1 and 2 or 1
				
				continue;
			end
		else
			lastColor = colorPicked
			amountColorHit = 0
		end
	end
	currentBet = minBet
end

local endingBalance = startingBalance - balance
print(endingBalance >= 0 and "You won "..math.floor(endingBalance) or "You Lost "..math.floor(endingBalance * -1))

This is the code that I ended up creating, and from the results that you can see is that you should never rely on theoretic probability. The sample ended up being 50/50 with losing and winning. So maybe think next time before you say a number or color is “Bound to Hit”.

Lesson learned

2 Likes

Why is this post not centered


I’d recommend posting this to #help-and-feedback:creations-feedback (or #resources:community-resources)


Anyway, this looks really cool; I may play around with it later for other odds and probabilities