Created
June 9, 2019 12:59
-
-
Save elnikkis/e1a3c04d49c26d1ae0d8827cb0586366 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import random | |
def markov(n, p): | |
state = True | |
for i in range(n): | |
x = random.random() | |
if p > x: | |
state = not state | |
print(1 if state else 0, sep='', end='') | |
print() | |
def randstr(n, p): | |
for i in range(n): | |
x = random.random() | |
print(1 if p > x else 0, sep='', end='') | |
print() | |
if __name__ == '__main__': | |
markov(80, 0.99) | |
markov(80, 0.8) | |
markov(80, 0.5) | |
markov(80, 0.1) | |
randstr(80, 0.99) | |
randstr(80, 0.8) | |
randstr(80, 0.5) | |
randstr(80, 0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment