From 2cee14cb6a5613c4a4ede3e08ee7ebf3ac371fc1 Mon Sep 17 00:00:00 2001 From: Adolfo Delorenzo Date: Tue, 26 Dec 2023 14:39:08 -0600 Subject: [PATCH] Tue Dec 26 14:39:08 CST 2023 --- database.db | 0 gen_ports.sh | 22 ++++++++++++++++++++++ numbers_db.sqlite | Bin 8192 -> 8192 bytes 3 files changed, 22 insertions(+) create mode 100644 database.db create mode 100755 gen_ports.sh diff --git a/database.db b/database.db new file mode 100644 index 0000000..e69de29 diff --git a/gen_ports.sh b/gen_ports.sh new file mode 100755 index 0000000..1a61c82 --- /dev/null +++ b/gen_ports.sh @@ -0,0 +1,22 @@ +#!/opt/homebrew/bin/bash + +# Create a random number between 32768 and 65535 +RAND_NUM=$(($RANDOM % (65536 - 32768) + 32768)) + +# SQLite database setup +DB_PATH="database.db" +CREATE_TABLE="CREATE TABLE IF NOT EXISTS ids (id INTEGER PRIMARY KEY)" +INSERT_INTO="INSERT OR IGNORE INTO ids(id) VALUES ($1)" +SELECT_EXISTS="SELECT EXISTS (SELECT 1 FROM ids WHERE id = $1)" + +# Check if the generated number already exists in the database +if [ $(sqlite3 "$DB_PATH" -header -separator "," -csv "SELECT $SELECT_EXISTS FROM ids WHERE id = '$RAND_NUM'" | awk '{print $1}') == 0 ]; then + # Number is unique, print it and insert into the database + echo "Unique random number: $RAND_NUM" + sqlite3 "$DB_PATH" -header -separator "," -csv "INSERT OR IGNORE INTO ids(id) VALUES ($RAND_NUM)" +else + # Number is not unique, generate a new random number and repeat the process + echo "Number already exists. Generating a new one..." + RAND_NUM=$(($RANDOM % (65536 - 32768) + 32768)) + echo "Unique random number: $RAND_NUM" +fi diff --git a/numbers_db.sqlite b/numbers_db.sqlite index 151b57e7d7a70a7ca7cbbb04e52fd8c4a8ba0577..6b9f7f98c6a775e15cb76945dac1b22732a6ae61 100644 GIT binary patch delta 169 zcmWN{u?@m75CFgghla)jzyd^i$+6$@n<^4w1bW`s?&%{Dn1Gb@6qIBa_Fx54U2{V> zbdPmejhlU0O{bS!3E3C&E8nu8E(bXd+iNYvQ6!FvIArk7YCw(+1j+ss&AZW+n8nl5G8oM-9 Ge0F~&zbpCx delta 351 zcmWO0F-k-+5P;#VtL|3sfvuKe5g5qiC6h@fcmYA|O(scYV=wF;L65MYV7raI{T3GD z5o|3LY)t?0^RLg>=MTrT<>Sf4Y`ML88jlvkPK_Vq%XmLtj;F)#u-o3f4lBKwU(bc9 z+B_MUYRll7Ltv~7DA_qAk|;%e-Ri?`oAr}4G>{^78={9qG=X4nEwJ_0C$)Lj2i+Qn z9FkhntPckFFV!Fq