Groovy web console

subscribe to the feed Subscribe
to this
site
Random Looser (via #groovywebconsole)
tweet this snippet Tweet
this
script

Random Looser

Published 1 month ago by Random Looser with tags Random
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import java.security.SecureRandom

def low = 0
def high = 0
def random = new SecureRandom("AAAAA1".bytes)
def nextSign = '>'
def balance = 8000
def bet = 10
def baseBet = 10
def looseSteak = 0
def winOnLow = 0
def winOnHigh = 0

for (i in 1..10000) {
    int rand = random.nextInt(10000)

    if (baseBet < 10) {
        baseBet = 10
    }

    if (rand <= 1000) {
        if (nextSign == '<') {
            winOnLow++
        }
        low++
    }
    if (rand >= 8999) {
        if (nextSign == '>') {
            winOnHigh++
        }
        high++
    }

    balance -= bet

    if ((rand >= 8999 && nextSign == '>') || (rand <= 1000 && nextSign == '<')) {
        balance += (bet * 9.9)
        bet = baseBet
        looseSteak = 0
    } else {
        looseSteak++
        bet += 1
    }

    if (high > 0 && low / high > 1) {
        nextSign = ">"
    }

    if(low > 0 && high / low > 1) {
        nextSign = "<"
    }

    if (bet >= balance) {
        println "Loose"
        break;
    }
}

println "$low/$winOnLow"
println "$high/$winOnHigh"
println balance