/* idea of generating password using the Diceware technique:

   https://theworld.com/~reinhold/diceware.html

   a tab-separated file of dicerolls and words
   https://theworld.com/~reinhold/diceware.wordlist.asc

   first stripped header and footer off diceware-file.txt
   to create diceware-wordlist.txt (by hand)

   then  replace ' and " with _ and __, respectively:
   cat diceware-wordlist.txt | sed "s/\'/_/g" | sed 's/\"/__/g' \
     > wordlist.txt

   We need a couple of new SQL features:
*/

SELECT abs(random())%10 AS n
FROM (SELECT 1);

SELECT 1+abs(random())%6 AS n
FROM (SELECT 1);

SELECT 'Eugene ' || 'Wallingford';

/*
   create *views* for each, save in random-view.sql
*/

.read random-view.sql
SELECT n||n||n||n||n FROM RandomDigit;
SELECT n||n||n||n||n FROM RandomDie;

CREATE TABLE WordList(diceroll, word);
.mode tabs
.import 'wordlist.txt' WordList
SELECT * FROM WordList
WHERE diceroll = '11113';
-- 11113 a_s

SELECT word FROM WordList
WHERE diceroll =
      (SELECT n||n||n||n||n FROM RandomDie);

/* Diceware creates three-word passphrases.  */

-- boo
SELECT word, word, word FROM WordList
WHERE diceroll = (SELECT n||n||n||n||n FROM RandomDie);

-- idea:
CREATE VIEW OneRoll AS
  SELECT word FROM WordList
  WHERE diceroll = (SELECT n||n||n||n||n FROM RandomDie);

SELECT word FROM OneRoll;
SELECT word FROM OneRoll;

-- yea!
SELECT Word1.word, Word2.word, Word3.word FROM
  (SELECT * FROM OneRoll) AS Word1,
  (SELECT * FROM OneRoll) AS Word2,
  (SELECT * FROM OneRoll) AS Word3;
-- save this gen-password.sql

.save diceware.db
.quit              /* with OneRoll now in database */

/* sqlite3 diceware.db < gen-password.sql

   #!/usr/bin/env bash
   sqlite3 diceware.db < gen-password.sql    */
