python 我将一个简单的脚本快速拼凑在一起,以概率运行简单的AP统计模拟。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 我将一个简单的脚本快速拼凑在一起,以概率运行简单的AP统计模拟。相关的知识,希望对你有一定的参考价值。

# Faizaan Datoo Pd3
# A very simple example of using technology to automate simulations :)
# I /could/ have made it more complicated, but that would defeat the point!

import random

print "Enter a range of digits."

# Get those numbers...
minVal = input("\tYour minimum value: ")
maxVal = input("\tYour maximum value: ")
repetitions = input("\tAmount of repetitions: ")
ignoreRepeats = raw_input("\tIgnore repeats? (y/n): ")

print "Okay, crunching some numbers..."
tries = []

for i in range(repetitions):
    print "=== Repetition #" + str(i + 1) + " ==="
    times = 0
    history = []
    
    while True:
        # Generate random values, print them out
        generated = random.randrange(minVal, maxVal)

        # Check for duplicates if we have to!
        if ignoreRepeats == "y":
            while (generated in history):
                generated = random.randrange(minVal, maxVal)
            history.append(generated)
            
        print str(generated) + " ",

        # Increment the times value to show we chose another guy
        times += 1
        
        # If it's less than 8 (i.e. 01 to 07), we got it, so end the repetition
        if(generated < 8): 
            print "| " + str(times) + " tries"
            tries.append(times)
            break

# Get the mean and print it, we're done
mean = sum(tries) / float(len(tries))
print "It took an average of " + str(mean) + " tries overall."

以上是关于python 我将一个简单的脚本快速拼凑在一起,以概率运行简单的AP统计模拟。的主要内容,如果未能解决你的问题,请参考以下文章

使用Excel拼凑SQL语句

NSTableView - 初始选择灰色,直到点击(焦点)

将 ggplotly 和 ggplot 与拼凑在一起?

使用 python nmap 模块扫描从先前扫描生成的主机

第一课

数字IC验证进阶以一个实例,快速上手python脚本处理log的若干关键操作(#python#正则表达式)