title: how do you auto generate a random ID for an SQLite database table
body: <p>Im in the process of creating a website with python flask and html. I want it to have a register, login, edit, delete, and home page. I want to store the users login data in an sqlite database that can then be called to veify the login of the user. in order to have different users have the same username and/or password, I need to give each user a unique ID. I use this ID in the url, and I want the user to be able to use this ID for other things in the website. because of this, when a new user is added I need to give them a random (unique) ID (probably 8 digits). I saw a bunch of stuff about <code> AUTO INCRAMENT</code> being random, but I didnt understand it very much, and I tried it, and it gave me consecutive numbers (which is not what I want) I also tried <code>RANDOM()</code> and <code>RAND()</code> but they both threw syntax errors. can anyone tell me how to generate an sqlite column for an random unique 8 digit ID?</p>
  <p>here's what I have:</p>
  <p>schema.sql</p>
  <pre><code>DROP TABLE IF EXISTS users;
  
  CREATE TABLE users (
      id INTEGER PRIMARY KEY --insert random generator here,
      username TEXT NOT NULL,
      password1 TEXT NOT NULL,
      created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
  );
  </code></pre>
  <p>heres the python that runs the schema:</p>
  <p>init_db.py</p>
  <pre><code>import sqlite3
  
  connection = sqlite3.connect('database.db')
  
  
  with open('schema.sql') as f:
     connection.executescript(f.read())
  
  cur = connection.cursor()
  
  cur.execute(&quot;INSERT INTO users (username, password1) VALUES (?, ?)&quot;,
             ('user1', 'pass1')
             )
  
  cur.execute(&quot;INSERT INTO users (username, password1) VALUES (?, ?)&quot;,
             ('user2', 'pass2')
             )
  
  connection.commit()
  connection.close()
  </code></pre>
  <p>thanks in advance for any help</p>