From f8aa65e6bc185eb12be8c3aa4c7677e562e6d86d Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 27 Jan 2021 15:51:37 -0800 Subject: [PATCH 1/4] Replace random with secrets.random --- markovify/chain.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/markovify/chain.py b/markovify/chain.py index 5d8e6de..6ad64d4 100644 --- a/markovify/chain.py +++ b/markovify/chain.py @@ -1,4 +1,5 @@ import random +import secrets import operator import bisect import json @@ -111,7 +112,8 @@ def move(self, state): else: choices, weights = zip(*self.model[state].items()) cumdist = list(accumulate(weights)) - r = random.random() * cumdist[-1] + # r = random.random() * cumdist[-1] + r = secrets.choice([random.random(), random.random()]) * cumdist[-1] selection = choices[bisect.bisect(cumdist, r)] return selection From b1ae89c4c616eec6d3e5836579a8eebee1b94439 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 27 Jan 2021 15:53:00 -0800 Subject: [PATCH 2/4] Replace random with secrets.random --- markovify/text.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/markovify/text.py b/markovify/text.py index 3a8360b..bba6567 100644 --- a/markovify/text.py +++ b/markovify/text.py @@ -1,6 +1,7 @@ import re import json import random +import secrets from .splitters import split_into_sentences from .chain import Chain, BEGIN, END from unidecode import unidecode @@ -262,7 +263,9 @@ def make_sentence_with_start(self, beginning, strict=True, **kwargs): # check for starting with begin as well ordered lists if tuple(filter(lambda x: x != BEGIN, key))[:word_count] == split ] - random.shuffle(init_states) + #random.shuffle(init_states) + for i in range(secrets.choice([1, 2])): + random.shuffle(init_states) else: err_msg = "`make_sentence_with_start` for this model requires a string containing 1 to {0} words. Yours has {1}: {2}".format(self.state_size, word_count, str(split)) raise ParamError(err_msg) From 7584f621eba2f455c65463fd7b8d5b089ab49b4d Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 30 Jan 2021 00:32:50 -0800 Subject: [PATCH 3/4] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9ce510b..84cc5cf 100644 --- a/README.md +++ b/README.md @@ -273,6 +273,7 @@ print(combined_model.make_sentence()) - [fakesocial](https://fakesocial.net), Fake social network using generated content. [[code](https://github.com/berfr/fakesocial)] - [Slovodel Bot](https://github.com/weiss-d/slovodel-bot), a Telegram bot that generates non-existent Russian words using corpus made by algorithmically dividing existent words into syllables. - [Deuterium](https://github.com/portasynthinca3/deuterium) is a Discord bot that generates messages on its own, after analyzing yours, and learning constantly. There's also a global model shared with all other servers. +- [Markovify Piano]https://github.com/asigalov61/Markovify-Piano) Coherent and plausible Piano music generation with Markov-chain/model. Have other examples? Pull requests welcome. From bcf42a36944af53aa11900e4c9f51a103ec1c87d Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 30 Jan 2021 00:33:18 -0800 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 84cc5cf..0b7e0cc 100644 --- a/README.md +++ b/README.md @@ -273,7 +273,7 @@ print(combined_model.make_sentence()) - [fakesocial](https://fakesocial.net), Fake social network using generated content. [[code](https://github.com/berfr/fakesocial)] - [Slovodel Bot](https://github.com/weiss-d/slovodel-bot), a Telegram bot that generates non-existent Russian words using corpus made by algorithmically dividing existent words into syllables. - [Deuterium](https://github.com/portasynthinca3/deuterium) is a Discord bot that generates messages on its own, after analyzing yours, and learning constantly. There's also a global model shared with all other servers. -- [Markovify Piano]https://github.com/asigalov61/Markovify-Piano) Coherent and plausible Piano music generation with Markov-chain/model. +- [Markovify Piano](https://github.com/asigalov61/Markovify-Piano) Coherent and plausible Piano music generation with Markov-chain/model. Have other examples? Pull requests welcome.