Exemple d’aléatoire pipé

# -*- coding: utf-8 -*-
import random
 
ROLLS_COUNT = 100000
 
# Essai totalement aléatoire
criticalCount = 0
maxMissedStraight = 0
missedStraight = 0
maxCriticalStraight = 0
criticalStraight = 0
for i in range(1, ROLLS_COUNT):
    roll = random.randint(1,100)
    if roll == 100:
        criticalCount += 1
        missedStraight = 0
        criticalStraight += 1
        if criticalStraight > maxCriticalStraight:
            maxCriticalStraight = criticalStraight
    else:
        criticalStraight = 0
        missedStraight += 1
        if missedStraight > maxMissedStraight:
            maxMissedStraight = missedStraight
 
print("(Régulier) On a eut %d critiques (%f %%), avec un maximum de \
%d ratés de suite et de %d critiques de suite." % (criticalCount, \
(float(criticalCount) / float(ROLLS_COUNT) * 100.0), maxMissedStraight, \
 maxCriticalStraight))
 
# Essai pipé
criticalCount = 0
maxMissedStraight = 0
missedStraight = 0
maxCriticalStraight = 0
criticalStraight = 0
previousRangeStart = 1
for i in range(1, ROLLS_COUNT):
    try:
        roll = random.randint(previousRangeStart,100)
    except ValueError:
        # Ce cas se présente lorsque les chances sont de 100%
        roll = 100
    if roll == 100:
        criticalCount += 1
        missedStraight = 0
        criticalStraight += 1
        previousRangeStart = 1
        if criticalStraight > maxCriticalStraight:
            maxCriticalStraight = criticalStraight
    else:
        criticalStraight = 0
        missedStraight += 1
        previousRangeStart += 1
        if missedStraight > maxMissedStraight:
            maxMissedStraight = missedStraight
 
print("(Pipé)     On a eut %d critiques (%f %%), avec un maximum de \
%d ratés de suite et de %d critiques de suite." % (criticalCount, \
(float(criticalCount) / float(ROLLS_COUNT) * 100.0), maxMissedStraight, \
 maxCriticalStraight))
  1. Pas encore de commentaire
  1. Pas encore de trackbacks