• random quote extractor?

    From J. P. Gilliver@21:1/5 to All on Wed Jun 18 11:43:22 2025
    XPost: alt.comp.software.thunderbird

    Anyone know of a utility that will extract a quote, at random, from a
    file of quotes (separated by a given string, which I could change easily
    enough - currently using "%%"), that will work under a 64-bit OS? The
    one I used to use [TomQuote] is I think 16 bit, and won't.

    (And no, I can't use a VM, for legal reasons.)
    --
    J. P. Gilliver. UMRA: 1960/<1985 MB++G()AL-IS-Ch++(p)Ar@T+H+Sh0!:`)DNAf
    

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Elvidge@21:1/5 to J. P. Gilliver on Wed Jun 18 12:53:46 2025
    XPost: alt.comp.software.thunderbird

    On 18/06/2025 at 11:43, J. P. Gilliver wrote:
    Anyone know of a utility that will extract a quote, at random, from a
    file of quotes (separated by a given string, which I could change easily enough - currently using "%%"), that will work under a 64-bit OS? The
    one I used to use [TomQuote] is I think 16 bit, and won't.

    (And no, I can't use a VM, for legal reasons.)

    https://www.bgreco.net/fortune

    --
    Chris Elvidge, England
    GRAMMAR IS NOT A TIME OF WASTE

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J. P. Gilliver@21:1/5 to Chris on Wed Jun 18 16:53:32 2025
    XPost: alt.comp.software.thunderbird

    On 2025/6/18 13:51:49, Chris wrote:
    J. P. Gilliver <G6JPG@255soft.uk> wrote:
    Anyone know of a utility that will extract a quote, at random, from a
    file of quotes (separated by a given string, which I could change easily
    enough - currently using "%%"), that will work under a 64-bit OS? The
    one I used to use [TomQuote] is I think 16 bit, and won't.

    (And no, I can't use a VM, for legal reasons.)

    I would put your list of quotes as individual entries in a simple database

    That sounds like a lot of work …

    like SQLite and then run this SQL statement:

    SELECT * FROM my_quotes ORDER BY RANDOM() LIMIT 1;

    … but that is a very elegant solution, and I appreciate your skill with
    the language involved. (I'll have a look at Chris Elvidge's solution
    first.)>
    Completely portable.

    Assuming you have a machine with an interpreter/compiler for whatever
    language that line is written in.
    --
    J. P. Gilliver. UMRA: 1960/<1985 MB++G()AL-IS-Ch++(p)Ar@T+H+Sh0!:`)DNAf
    

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J. P. Gilliver@21:1/5 to Chris Elvidge on Wed Jun 18 17:21:49 2025
    XPost: alt.comp.software.thunderbird

    On 2025/6/18 12:53:46, Chris Elvidge wrote:
    On 18/06/2025 at 11:43, J. P. Gilliver wrote:
    Anyone know of a utility that will extract a quote, at random, from a
    file of quotes (separated by a given string, which I could change
    easily enough - currently using "%%"), that will work under a 64-bit
    OS? The one I used to use [TomQuote] is I think 16 bit, and won't.

    (And no, I can't use a VM, for legal reasons.)

    https://www.bgreco.net/fortune

    Thanks for that.

    Looks a bit complicated for me. If I implemented it, and wanted to just
    get a random quote, would I have to invoke powershell with it as a
    parameter - something like "powershell <fortune>"? (And could I direct
    its output to a file, ideally with ">>" so it could _append_ to such a
    file)?

    I see the supplied fortune.txt has fortunes separated by "%" lines. Mine
    has "%%" lines. Could I just change

    -split "`n%`n"

    with

    -split "`n%%`n"

    in the two methods shown, or would it just be easier/safer to do a
    global change in my quotes file?
    --
    J. P. Gilliver. UMRA: 1960/<1985 MB++G()AL-IS-Ch++(p)Ar@T+H+Sh0!:`)DNAf
    

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From MikeS@21:1/5 to J. P. Gilliver on Wed Jun 18 21:23:53 2025
    XPost: alt.comp.software.thunderbird

    On 18/06/2025 11:43, J. P. Gilliver wrote:
    Anyone know of a utility that will extract a quote, at random, from a
    file of quotes (separated by a given string, which I could change easily enough - currently using "%%"), that will work under a 64-bit OS? The
    one I used to use [TomQuote] is I think 16 bit, and won't.

    (And no, I can't use a VM, for legal reasons.)

    If the old 16 bit program does all you want there is a good chance it
    will work in Windows 10 or 11 with a utility called otvdm https://mendelson.org/otvdm.html
    It is trivial to install and your program will then simply run. It is
    based on Wine but nothing like running a VM and I have used it for years without problems.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Louis Krupp@21:1/5 to J. P. Gilliver on Wed Jun 18 15:57:51 2025
    XPost: alt.comp.software.thunderbird

    This is a multi-part message in MIME format.
    On 6/18/2025 4:43 AM, J. P. Gilliver wrote:
    Anyone know of a utility that will extract a quote, at random, from a
    file of quotes (separated by a given string, which I could change
    easily enough - currently using "%%"), that will work under a 64-bit
    OS? The one I used to use [TomQuote] is I think 16 bit, and won't.

    (And no, I can't use a VM, for legal reasons.)

    If you don't mind installing Python, you could try a quick and dirty
    program like this:

    import random

    with open("tq.txt", "r") as qf:
        quotes = qf.read()

    quote_array = quotes.split("%%")

    random.seed()
    print(quote_array[random.randint(0, len(quote_array) - 1)])

    The input file (tq.txt) looks like this:

    I hate computers.
    %%
    The square root of 5 is 2 for small values of 5 and large values of 2.
    %%
    The more I ponder the principles of language design, and the techniques
    which put them into practice, the more is my amazement and admiration of
    ALGOL 60. Here is a language so far ahead of its time, that it was not
    only an improvement on its predecessors, but also on nearly all its
    successors.
    -- C. A. R. Hoare, 1973
    %%
    You don't manage people; you manage things. You lead people.
    -- Rear Admiral Grace Hopper

    The program runs on my Linux box.

    Louis
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
    <div class="moz-cite-prefix">On 6/18/2025 4:43 AM, J. P. Gilliver
    wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:102u58b$320gt$4@dont-email.me">Anyone
    know of a utility that will extract a quote, at random, from a
    file of quotes (separated by a given string, which I could change
    easily enough - currently using "%%"), that will work under a
    64-bit OS? The one I used to use [TomQuote] is I think 16 bit, and
    won't.
    <br>
    <br>
    (And no, I can't use a VM, for legal reasons.)
    <br>
    </blockquote>
    <br>
    If you don't mind installing Python, you could try a quick and dirty
    program like this:<br>
    <blockquote>import random<br>
    <br>
    with open("tq.txt", "r") as qf:<br>
        quotes = qf.read()<br>
    <br>
    quote_array = quotes.split("%%")<br>
    <br>
    random.seed()<br>
    print(quote_array[random.randint(0, len(quote_array) - 1)])<br>
    </blockquote>
    The input file (tq.txt) looks like this:<br>
    <blockquote>I hate computers.<br>
    %%<br>
    The square root of 5 is 2 for small values of 5 and large values
    of 2.<br>
    %%<br>
    The more I ponder the principles of language design, and the
    techniques<br>
    which put them into practice, the more is my amazement and
    admiration of<br>
    ALGOL 60. Here is a language so far ahead of its time, that it was
    not<br>
    only an improvement on its predecessors, but also on nearly all
    its<br>
    successors.<br>
    -- C. A. R. Hoare, 1973<br>
    %%<br>
    You don't manage people; you manage things. You lead people.<br>
    -- Rear Admiral Grace Hopper<br>
    </blockquote>
    The program runs on my Linux box.<br>
    <br>
    Louis<br>
    </body>
    </html>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul@21:1/5 to J. P. Gilliver on Wed Jun 18 18:21:14 2025
    XPost: alt.comp.software.thunderbird

    On Wed, 6/18/2025 6:43 AM, J. P. Gilliver wrote:
    Anyone know of a utility that will extract a quote, at random, from a file of quotes (separated by a given string, which I could change easily enough - currently using "%%"), that will work under a 64-bit OS? The one I used to use [TomQuote] is I think
    16 bit, and won't.

    (And no, I can't use a VM, for legal reasons.)

    One way of doing it, is to put all materials into just one file,
    compile, and now the EXE has all resources needed.

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <Windows.h>

    /* gcc -o randstmt.exe randstmt.c */
    /* mingw32 installation... */

    /* Some strings strng[0], strng[1], strng[2], plus an end marker as strng[3] */ /* Add statements and recompile */

    /* To be triggered manually by the user.
    These are not really random numbers, but want to avoid linking in ugly DLLs */

    int main() { /* The first chunk here, is your collection of thoughtful observations */

    char *strng[] = {
    "To air is human.\n To dust, divine.\n",
    "When life gives you lemons\n open a used car lot\n",
    "A transcendental plan \n is better than no dental plan at all.\n",
    "End"
    };

    int i = 0;
    int j = 0;
    __int64 now;

    QueryPerformanceCounter((LARGE_INTEGER *) &now); /* vaguely related to RDTSC ? */
    printf("0x%I64X \n", now); /* Debug the range of the random numbers -- remove after testing */

    while (strcmp(strng[i], "End") != 0) { /* This measures the number of statements in names[] */
    i++ ;
    } /* statements mod i */

    j = now % i ;
    printf("%d\n", j); /* Debug the range of the random numbers -- remove after testing */

    printf( strng[ j ] ); /* Use printf punctuation, such as \n , for crude formatting */
    exit(0);
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Herbert Kleebauer@21:1/5 to J. P. Gilliver on Thu Jun 19 00:29:16 2025
    XPost: alt.comp.software.thunderbird

    On 18.06.2025 12:43, J. P. Gilliver wrote:

    Anyone know of a utility that will extract a quote, at random, from a
    file of quotes (separated by a given string, which I could change easily enough - currently using "%%"), that will work under a 64-bit OS? The
    one I used to use [TomQuote] is I think 16 bit, and won't.

    The following batch will convert the "quotes.txt" input file
    to a batch file (q.bat). When you execute q.bat, a random
    quote is displayed. But to use batch control characters (like ^ & %)
    in the text, you have to escape them (^^ ^& %%).

    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

    @echo off
    echo @echo off>q.bat
    echo echo.>>q.bat
    echo goto :start>>q.bat
    echo :l0>>q.bat
    set /a n=1

    for /f "tokens=*" %%i in (quotes.txt) do (
    if "%%i"=="%%%%" (
    echo echo.>>q.bat
    echo goto :eof>>q.bat
    call echo :l%%n%%>>q.bat
    set /a n=n+1) else (
    echo echo %%i>>q.bat)
    )
    echo echo.>>q.bat
    echo goto :eof>>q.bat
    echo :start>>q.bat

    echo set /a m=%%random%%>>q.bat
    echo set /a m=%%random%%%%%%%n%>>q.bat
    echo goto :l%%m%%>>q.bat

    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

    For the input file quotes.txt:

    Life isn't about getting and having, it's about giving and being.
    Kevin Kruse
    %%
    Whatever the mind of man can conceive and believe, it can achieve.
    Napoleon Hill
    %%
    Strive not to be a success, but rather to be of value.
    Albert Einstein
    %%
    Two roads diverged in a wood, and I-I took the one less traveled
    by, And that has made all the difference.
    Robert Frost
    %%
    I attribute my success to this: I never gave or took any excuse.
    Florence Nightingale
    %%
    You miss 100%% of the shots you don't take.
    Wayne Gretzky
    %%
    I've missed more than 9000 shots in my career. I've lost almost
    300 games. 26 times I've been trusted to take the game winning shot
    and missed. I've failed over and over and over again in my life.
    And that is why I succeed.
    Michael Jordan

    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

    the following q.bat is generated:

    @echo off
    echo.
    goto :start
    :l0
    echo Life isn't about getting and having, it's about giving and being.
    echo Kevin Kruse
    echo.
    goto :eof
    :l1
    echo Whatever the mind of man can conceive and believe, it can achieve.
    echo Napoleon Hill
    echo.
    goto :eof
    :l2
    echo Strive not to be a success, but rather to be of value.
    echo Albert Einstein
    echo.
    goto :eof
    :l3
    echo Two roads diverged in a wood, and I-I took the one less traveled
    echo by, And that has made all the difference.
    echo Robert Frost
    echo.
    goto :eof
    :l4
    echo I attribute my success to this: I never gave or took any excuse.
    echo Florence Nightingale
    echo.
    goto :eof
    :l5
    echo You miss 100%% of the shots you don't take.
    echo Wayne Gretzky
    echo.
    goto :eof
    :l6
    echo I've missed more than 9000 shots in my career. I've lost almost
    echo 300 games. 26 times I've been trusted to take the game winning shot
    echo and missed. I've failed over and over and over again in my life.
    echo And that is why I succeed.
    echo Michael Jordan
    echo.
    goto :eof
    :start
    set /a m=%random%
    set /a m=%random%%%7
    goto :l%m%

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J. P. Gilliver@21:1/5 to All on Wed Jun 18 23:35:18 2025
    XPost: alt.comp.software.thunderbird

    T24gMjAyNS82LzE4IDI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mtzIC0gdGhhdCdzIHdvbmRlcmZ1bCEgQm90 aCB0aGUgb2xkIERPUyBjb21tYW5kcyBJIG5lZWQgKHRoZSBvbmUgDQp0aGF0IGV4dHJhY3Rz IGEgcmFuZG9tIHF1b3RlLCBhbmQgdGhlIG9uZSB0aGF0IHJlLWluZGV4ZXMgdGhlIGZpbGUg YWZ0ZXIgDQpJJ3ZlIG1vZGlmaWVkIHRoZSBxdW90ZXMgZmlsZSkgd29yayB1bmRlciBpdCEN Ci0tIA0KSi4gUC4gR2lsbGl2ZXIuIFVNUkE6IDE5NjAvPDE5ODUgTUIrK0coKUFMLUlTLUNo KysocClBckBUK0grU2gwITpgKUROQWYNCgANCk5vLiBJIGRlbXVyLiBMZXQgaXQgW3RoZSBS b3lhbCBWYXJpZXR5IFBlcmZvcm1hbmNlXSBnbGl0dGVyIHJpZGljdWxvdXNseSANCm9uLCB0 byBhZmZpcm0gdGhhdCBvdGhlciBwZW9wbGUncyBwbGVhc3VyZXMsIGV2ZW4gZ2hhc3RseSBv bmVzLCBhcmUgcGFydCANCm9mIHRoZSBncmVhdCBtb3VsZHkgcGF0Y2h3b3JrIGNsb3duLXRy b3VzZXIgb2YgdGhlIG5hdGlvbi4gLSBMaWJieSANClB1cnZlcywgcnQgMjAyMi8xMi8xNy0y
    Mw0K

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul@21:1/5 to J. P. Gilliver on Wed Jun 18 23:55:07 2025
    XPost: alt.comp.software.thunderbird

    On Wed, 6/18/2025 11:53 AM, J. P. Gilliver wrote:
    On 2025/6/18 13:51:49, Chris wrote:
    J. P. Gilliver <G6JPG@255soft.uk> wrote:
    Anyone know of a utility that will extract a quote, at random, from a
    file of quotes (separated by a given string, which I could change easily >>> enough - currently using "%%"), that will work under a 64-bit OS? The
    one I used to use [TomQuote] is I think 16 bit, and won't.

    (And no, I can't use a VM, for legal reasons.)

    I would put your list of quotes as individual entries in a simple database

    That sounds like a lot of work …

    like SQLite and then run this SQL statement:

    SELECT * FROM my_quotes ORDER BY RANDOM() LIMIT 1;

    … but that is a very elegant solution, and I appreciate your skill with the language involved. (I'll have a look at Chris Elvidge's solution first.)>
    Completely portable.

    Assuming you have a machine with an interpreter/compiler for whatever language that line is written in.

    This is the current site.

    https://sqlite.org/download.html

    sqlite-tools-win-x64-3500100.zip (6.13 MiB)

    A bundle of command-line tools for managing SQLite database files, including
    (1) the command-line shell <=== sqlite3.exe or similar... That's what I would look for.
    (2) sqldiff.exe
    (3) sqlite3_analyzer.exe
    (4) sqlite3_rsync.exe 64-bit

    Mine is 3.39.4.0 2022-09-29 (3.39.4) This is a 32 bit version, suited to some situations.

    https://web.archive.org/web/20221012234637/https://sqlite.org/download.html

    sqlite-tools-win32-x86-3390400.zip (1.88 MiB)

    A bundle of command-line tools for managing SQLite database files, including
    command-line shell program <=== sqlite3.exe or similar...
    sqldiff.exe program,
    sqlite3_analyzer.exe program.

    First, prepare the file that will create the database. I don't know
    a thing about this topic, but I have done .dump on Firefox sqlite3 files before, so I knew where to go to find a copy/paste example :-) The
    only thing I forgot on my first try, is I forgot the COMMIT line :-)
    No guarantees what I've done is "right", it's just a pale imitation
    of a file.

    ***** fortune.sql *****
    PRAGMA foreign_keys=OFF;
    BEGIN TRANSACTION;
    CREATE TABLE fortunes ( id INTEGER PRIMARY KEY, fortune LONGVARCHAR );
    INSERT INTO fortunes VALUES( 1,'I was working on the railroad, the live long day.');
    INSERT INTO fortunes VALUES( 2,'Pack my jug with five dozen boxes.');
    INSERT INTO fortunes VALUES( 3,'Mary had lamb chops, as white as snow.'); INSERT INTO fortunes VALUES( 4,'My hovercraft is full of spineless invertebrates');
    COMMIT;
    ***** fortune.sql *****

    echo .read fortune.sql | sqlite3 fortunes.sqlite3 # Loaded

    sqlite3 fortunes.sqlite3 # Interactive

    sqlite> SELECT * FROM fortunes ORDER BY RANDOM() LIMIT 1;
    4|My hovercraft is full of spineless invertebrates
    sqlite> .exit

    Still work to do, you need to clean up some details
    to make this fit for purpose. But at least I was able
    to extract a line.

    The first thing I notice, is I suspect it's using RAND() to
    generate the numbers, and in my C code, I had to stop doing
    that because I was tapping the same sequence each time. Not good.
    Still some research to do, on a better seed and generator, as
    even when I seeded my RAND() I wasn't happy with what I was
    seeing from session to session.

    It's not getting a text line that is tough, it's nailing
    the randomness that is hard.

    My CPU has a feature (Zen3) where it can generate 500 million bytes
    of random numbers per second, using a metastability based generator
    of some sort. This is a non-cryptographic source of random numbers.
    Nobody on the OS sides would touch that with a barge pole, but
    it neatly avoids seed and sequence issues. The solution is not
    all that portable, as the generators in hardware vary from
    none at all, to lousy-implementation, to so-so implementation
    with post-whitener to make it minty fresh. Anything that produces
    random numbers that quickly, can't be good :-)

    Name: rdrand.bin # The file on my S: drive from some experiment.
    Size: 1073741824 bytes (1024 MiB) # No idea what code I was using.

    Anyway, randomness is the challenge. Not the storing them in
    a table part.

    Paul

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul@21:1/5 to Chris on Thu Jun 19 14:57:40 2025
    XPost: alt.comp.software.thunderbird

    On Thu, 6/19/2025 5:10 AM, Chris wrote:


    Down side is you need recompile whenever you add new quotes.

    Large collection, no rush, as low odds of new item appearing (randomly).
    You could recompile your list once a month.

    It you were willing to keep state info, you could sort the lines
    randomly first, then serve like bog roll. That works better with
    the easily-accessible (pseudo) random number generators.

    Paul

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)