Shell script is easiest way to go
Some psedo code(not tested just how I would approach it)
#!/bin/sh
#Get connection to DB and select the count of book IDs
declare -a numOfBooks=$(sqlite3 /system/explorer-3/exlplorer-3.db "SELECT ID FROM BOOKS_IMPL")
#Use random to get an ID
size=${#numOfBooks[@]}
randomBookID=$(($RANDOM % $size))
#Somehow, invoke reader program to open the ID
|