diff --git a/README.md b/README.md index 9ce510b..0b7e0cc 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. 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 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)