code: def exampleRand(S, A):
      
      db = "MDP-%sx%s.db" % (S, A)
      if os.path.exists(db):
          os.remove(db)
      conn = sqlite3.connect(db)
      with conn:
          c = conn.cursor()
          cmd = '''
              CREATE TABLE info (name TEXT, value INTEGER);
              INSERT INTO info VALUES('states', %s);
              INSERT INTO info VALUES('actions', %s);''' % (S, A)
          c.executescript(cmd)
          for a in range(1, A+1):
              cmd = '''
                  CREATE TABLE transition%s (row INTEGER, col INTEGER, prob REAL);
                  CREATE TABLE reward%s (state INTEGER PRIMARY KEY ASC, val REAL);
                  ''' % (a, a)
              c.executescript(cmd)
              cmd = "INSERT INTO reward%s(val) VALUES(?)" % a
              c.executemany(cmd, zip(random(S).tolist()))
              for s in xrange(1, S+1):
                  # to be usefully represented as a sparse matrix, the number of
                  # nonzero entries should be less than 1/3 of dimesion of the
                  # matrix, so S/3
                  n = randint(1, S//3)
                  # timeit [90894] * 20330
                  # ==> 10000 loops, best of 3: 141 us per loop
                  # timeit (90894*np.ones(20330, dtype=int)).tolist()
                  # ==> 1000 loops, best of 3: 548 us per loop
                  col = (permutation(arange(1,S+1))[0:n]).tolist()
                  val = random(n)
                  val = (val / val.sum()).tolist()
                  cmd = "INSERT INTO transition%s VALUES(?, ?, ?)" % a
                  c.executemany(cmd, zip([s] * n, col, val))
              cmd = "CREATE UNIQUE INDEX Pidx%s ON transition%s (row, col);" % (a, a)
              c.execute(cmd)
      # return the name of teh database
      return db
docs: WARNING: This will delete a database with the same name as 'db'.