import statistics as stat
from statistics import mean
from random import seed, choice
from math import hypot
import random
from turtle import *
import statistics
from statistics import stdev
seed(20190101)
def random_walk(n):
x = 0
y = 0
for i in range(n):
step = random.choice(["N","S","E","W"])
if step == 'N':
y = y + 1
elif step == "S":
y = y - 1
elif step == "E":
x = x + 1
else:
x = x - 1
return (x,y)
all_steps = []
for i in range(50):
walk = random_walk(100)
all_steps.append(abs(walk[0]) + abs(walk[1]))
steps_mean = statistics.mean(all_steps) #Only after the loop
steps_max = max(all_steps)
steps_min = min(all_steps)
steps_variance = statistics.stdev(all_steps)
print("Max is",steps_max)
print("Mean is",steps_mean)
print("Min is",steps_min)
print("variance is",steps_variance)
print("Pa random walk of 100 steps")
for i in range(50):
walk = random_walk(1000)
all_steps.append(abs(walk[0]) + abs(walk[1]))
steps_mean = statistics.mean(all_steps) #Only after the loop
steps_max = max(all_steps)
steps_min = min(all_steps)
steps_variance = statistics.stdev(all_steps)
print("Max is",steps_max)
print("Mean is",steps_mean)
print("Min is",steps_min)
print("variance is",steps_variance)
print("Pa random walk of 1000 steps")
Hello, just a quick question: how do I set a seed value in python and keep it that way? Is this the correct way to do it? By just doing seed(20190101) at the beginning of my program. Will this set the seed for all of my functions as well? I could only find answers to the random seed module, not the specific one.