Markov: drop the max id stuff, get a bunch of chains and pick one randomly. cooler this way.

This commit is contained in:
Brian S. Stephan 2011-10-21 17:01:09 -05:00
parent e3ef3f48dc
commit 8c1ffc54ba
1 changed files with 2 additions and 4 deletions

View File

@ -521,10 +521,8 @@ class Markov(Module):
values = []
try:
db = self.get_db()
max_id = self._get_max_chain_id()
rand_id = random.randint(1,max_id)
query = 'SELECT k2 FROM markov_chain WHERE v = ? AND (context = ? OR context IS NULL) AND id >= {0:d} UNION SELECT k2 FROM markov_chain WHERE v = ? AND (context = ? OR context IS NULL) AND id < {1:d} LIMIT 1'.format(rand_id, rand_id)
cursor = db.execute(query, (v,context,v,context))
query = 'SELECT k2 FROM markov_chain WHERE v = ? AND (context = ? OR context IS NULL)'
cursor = db.execute(query, (v,context))
results = cursor.fetchall()
for result in results: