DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Select Random Line from Text File  (Read 14,994 times)

Verathis

  • Participant
  • Joined in 2008
  • *
  • Posts: 4
Select Random Line from Text File
« on: November 18, 2008, 01:38 AM »
I'm looking for a program that selects a random line from a text file of my choice. There was something similar done here. But I don't want the thing to increase the chance with numbers. Also, my list has 3 spaces in front of each entry due to the program I used to generate the list. :-[ Not sure if that's needed or not, since it would just be displaying a random line.

It seems simple in nature, but I'm horrible with actual programming languages, so if someone could write this up for me, I'd be very grateful. Or if it's already been done and I'm missing it, just toss me a link. I'd prefer it be an exe, but if there is a website that will eat my txt file and give me a random entry from it, that would work too!

mhb

  • There is no life before coffee!
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 22
Re: Select Random Line from Text File
« Reply #1 on: November 18, 2008, 10:52 AM »
Hi Verathis,

just had a couple of free minutes available right now.... so here is a very simple solution:

In the AHK script you can define a default text file if you want, otherwise just call the EXE with the textfile as an argument
Code
RandomLine_simple.exe MyQuotes.txt

I hope it helps...

Marc
There's nothing new under the sun,
but there are lots of old things we don't know. (Ambrose Bierce)

kartal

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 1,529
Re: Select Random Line from Text File
« Reply #2 on: November 18, 2008, 02:13 PM »
I hope that this kind of software is not used for "spamming"
« Last Edit: November 18, 2008, 02:18 PM by kartal »

jgpaiva

  • Artificial Idiocy
  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • Cody Award
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Portugal Inhabitant
    • Linux User
Re: Select Random Line from Text File
« Reply #3 on: November 18, 2008, 02:53 PM »
Verathis: With mhb's solution, you can also just drop the .txt file on the .exe file ;)

mhb

  • There is no life before coffee!
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 22
Re: Select Random Line from Text File
« Reply #4 on: November 18, 2008, 02:55 PM »
Hi kartal,

I don't think this program is going to support spamming, BUT I wouldn't be too surprised if suddenly somebody new to this forum suggests a website or tool "which is really good for this purpose"  ;)

Greetings,
Marc
There's nothing new under the sun,
but there are lots of old things we don't know. (Ambrose Bierce)

Verathis

  • Participant
  • Joined in 2008
  • *
  • Posts: 4
Re: Select Random Line from Text File
« Reply #5 on: November 18, 2008, 11:05 PM »
Wow, that works great! Thanks a ton, everybody!

And no, it's not for spamming. Not sure how it could be used for that anyway. But I plan on writing some reviews for a friend's website, and instead of me going through and picking each and every thing each time, I figured it'd be better to have something pick it randomly, as I have a rather huge list of things I can review (1600+).

Verathis

  • Participant
  • Joined in 2008
  • *
  • Posts: 4
Re: Select Random Line from Text File
« Reply #6 on: November 19, 2008, 12:23 AM »
mhb, would you happen to have the source for that exe? I'm a beginner in programming, and I'd like to see how that works.

mhb

  • There is no life before coffee!
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 22
Re: Select Random Line from Text File
« Reply #7 on: November 24, 2008, 12:44 PM »
Hi Verathis,

sorry to reply this late, but I am moving right now and had no internet access during the last days.
You can check the source code in the .ahk file, which is one of the attached downloads to my original reply. Just open that file in an editor and you have the source code...

I have to admit,  I didn't comment the code, which is really bad programming practice, but it was just a shorty :-)

Greetings,
Marc
There's nothing new under the sun,
but there are lots of old things we don't know. (Ambrose Bierce)

Verathis

  • Participant
  • Joined in 2008
  • *
  • Posts: 4
Re: Select Random Line from Text File
« Reply #8 on: December 01, 2008, 11:34 PM »
It's fine, I really wasn't in a hurry to get it. I'm fairly new to AHK, so I didn't know the source came in the .ahk file. Thanks for all the help!

Original address: https://www.donationcoder.com/forum/index.php?topic=15780.0