• Random Files

    From Thomas Bampi@2:333/808 to All on Wednesday, April 18, 2018 11:03:50
    Hi All! can you tell me a JS script that can take me in random files and copy them in a specific file?
    Example: I have files that are called logo.1, logo.2, logo.3, logo.4 etc ... the script randomly takes one of these files and copies it as logo.ans

    Thank you
    Thomas Bampi

    F. KrueGer
    --- SBBSecho 3.04-Win32
    * Origin: Veleno BBS - http://velenobbs.ddns.net (2:333/808)
  • From Bill McGarrity@1:266/404 to Thomas Bampi on Wednesday, April 18, 2018 13:45:00
    Thomas Bampi wrote to All on 04-18-18 11:03 <=-

    Hi All! can you tell me a JS script that can take me in random files
    and copy them in a specific file?
    Example: I have files that are called logo.1, logo.2, logo.3, logo.4
    etc ... the script randomly takes one of these files and copies it as logo.ans

    The logon.js will already do that for you. Just name your .asc files random1.asc, random2.asc and so on. Instaying with the 8.3 standard, you can make 99 of them.


    --

    Bill

    Telnet: tequilamockingbirdonline.net
    Web: bbs.tequilamockingbirdonline.net
    FTP: ftp.tequilamockingbirdonline.net:2121
    IRC: irc.tequilamockingbirdonline.net Ports: 6661-6670 SSL: +6697
    Radio: radio.tequilamockingbirdonline.net:8010/live


    ... Look Twice... Save a Life!!! Motorcycles are Everywhere!!!
    --- MultiMail/Win32 v0.50
    * Origin: TequilaMockingbird Online - Toms River, NJ (1:266/404)
  • From Digital Man@1:103/705 to Thomas Bampi on Wednesday, April 18, 2018 14:36:32
    Re: Random Files
    By: Thomas Bampi to All on Wed Apr 18 2018 11:03 am

    Hi All! can you tell me a JS script that can take me in random files and copy them in a specific file?
    Example: I have files that are called logo.1, logo.2, logo.3, logo.4 etc ... the script randomly takes one of these files and copies it as logo.ans

    This question is best asked in one of the Synchronet Programming related message areas, but here's a short example in JS:

    file_copy("logo." + random(4), "logo.ans");

    There's an even better example in exec/logon.js (search for "random").

    digital man

    Synchronet "Real Fact" #61:
    How to get Synchronet technical support: http://wiki.synchro.net/howto:support Norco, CA WX: 73.0øF, 30.0% humidity, 15 mph ENE wind, 0.00 inches rain/24hrs --- SBBSecho 3.04-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From poindexter FORTRAN@1:103/705 to Digital Man on Wednesday, April 18, 2018 18:41:32
    Re: Random Files
    By: Digital Man to Thomas Bampi on Wed Apr 18 2018 02:36 pm

    There's an even better example in exec/logon.js (search for "random").

    I was hoping for an algorithm that would pull a random line out of a text file, but then I broke up my text file into dozens of files with one line each.

    ---
    þ Synchronet þ realitycheckBBS -- http://realitycheckBBS.org
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Digital Man@1:103/705 to poindexter FORTRAN on Wednesday, April 18, 2018 22:49:26
    Re: Random Files
    By: poindexter FORTRAN to Digital Man on Wed Apr 18 2018 06:41 pm

    Re: Random Files
    By: Digital Man to Thomas Bampi on Wed Apr 18 2018 02:36 pm

    There's an even better example in exec/logon.js (search for "random").

    I was hoping for an algorithm that would pull a random line out of a text file, but then I broke up my text file into dozens of files with one line each.

    Pulling a random line is pretty easy too:

    var f = new File(fname);
    if(!f.open("r")) {
    alert("Error opening " + fname);
    exit();
    }

    var list = f.readAll();
    f.close();
    var i = random(list.length);

    var line = list[i]; // line is now a randomly chosen line from the file

    digital man

    This Is Spinal Tap quote #17:
    David St. Hubbins: It's such a fine line between stupid, and uh... and clever. Norco, CA WX: 53.0øF, 70.0% humidity, 5 mph E wind, 0.00 inches rain/24hrs
    --- SBBSecho 3.04-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From echicken@1:103/705 to poindexter FORTRAN on Thursday, April 19, 2018 11:35:58
    Re: Random Files
    By: poindexter FORTRAN to Digital Man on Wed Apr 18 2018 18:41:32

    I was hoping for an algorithm that would pull a random line out of a text

    file, but then I broke up my text file into dozens of files with one line

    each.

    var f = new File('lines');
    f.open('r');
    var lines = f.readAll();
    f.close();
    var line = lines[Math.floor(Math.random() * lines.length)];

    Something like that ort to work.

    ---
    echicken
    electronic chicken bbs - bbs.electronicchicken.com - 416-273-7230


    ---
    þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.com
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From poindexter FORTRAN@1:103/705 to Digital Man on Thursday, April 19, 2018 11:33:27
    Re: Random Files
    By: Digital Man to poindexter FORTRAN on Wed Apr 18 2018 10:49 pm

    Pulling a random line is pretty easy too:

    Easy for you! :)

    Thanks a lot -- this will clean up my install greatly and let me add lines much more easily than creating a new file each time I add a line.

    ---
    þ Synchronet þ realitycheckBBS -- http://realitycheckBBS.org
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)