Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 09, 2016, 01:51:39 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: Randomly select 'n' Lines from text list  (Read 4613 times)

magician62

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 118
    • View Profile
    • Donate to Member
IDEA: Randomly select 'n' Lines from text list
« on: December 18, 2011, 01:28:45 AM »
Simple idea, I think. :) Pulling names from a digital Hat

Provide a scrollable text area for the user to type of paste a list, each line being a new choice

Provide a means to define how many items to randomly select

Provide a second scrollable text area to display the results from the randomised selection, with a numerical identifier (for reference) and in their order of selection


Although I have found facilities on the net to, randomly select an item from a list. They seem only to pull 1 item, and there is a security risk of passing the list across the net



Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,784
    • View Profile
    • Donate to Member
Re: IDEA: Randomly select 'n' Lines from text list
« Reply #1 on: December 18, 2011, 05:34:21 AM »
Doesn't mouser have such an application for drawing winners of the raffles he held before? ;D

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,421
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: Randomly select 'n' Lines from text list
« Reply #2 on: December 18, 2011, 05:43:54 AM »
i do have a pretty powerful tool for this, Prize Optimizer (written about here), which does simulated annealing to optimize the distribution of multiple prizes to multiple people based on their rankings.

But it's never been released to public.. only because it gets its data from parsing email and i'd have to do a little bit of work to make it possible to manualy enter input data.

One one hand it's very useful as is since it will parse email entries with ranking and use them to create data, and then generate output emails notifying people what they won if anything.

With a bit of work i could make it so input could be done interactively.. but it's hard to justify if there are only 3 people on the planet who have any use for it.. seems like something that might be better done in modern times using an online web service..

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,784
    • View Profile
    • Donate to Member
Re: IDEA: Randomly select 'n' Lines from text list
« Reply #3 on: December 18, 2011, 05:45:15 AM »
Would be a very nice NANY entry :Thmbsup:

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,845
    • View Profile
    • Donate to Member
Re: IDEA: Randomly select 'n' Lines from text list
« Reply #4 on: December 18, 2011, 07:12:59 AM »
I'm thinking of putting the following into LBA (a Clipboard Help and Spell custom tool) -- haven't tested it much so it might be off.  I don't expect it to work well on a large number of choices, but who knows?

Setup would include installing and configuring LBA and putting the following in LBA's script folder.

To use, open an editor and put one choice on each line (and save a copy somewhere else).  Then select all of the choices, invoke LBA, and choose the menu entry associated with the saved script.  A dialog box should appear asking for how many items to choose and then afterwards the selected text should be replaced by an appropriate number of items.

Code: Autohotkey [Select]
  1. ChangeText(InputText)
  2. {
  3.   Lines := []
  4.   Pattern := "mO)^(.*)$"
  5.   Start := 1
  6.   Cnt := 0
  7.   While (True)
  8.   {
  9.     FoundPos := RegExMatch(InputText, Pattern, mObj, Start)
  10.     If (ErrorLevel != 0)
  11.     {
  12.       OutputDebug, % "RegExMatch ErrorLevel: " . ErrorLevel
  13.       SoundBeep
  14.       Return
  15.     }
  16.     If (FoundPos == 0)
  17.     {
  18.       Break
  19.     }
  20.     Start := FoundPos + 1
  21.     Lines.Insert(mObj[1])
  22.     Cnt := Cnt + 1
  23.   }
  24.   If (Cnt == 0)
  25.   {
  26.     Message := "Sorry, didn't find any lines"
  27.     OutputDebug, % Message
  28.     MsgBox, % Message
  29.     SoundBeep
  30.     Return
  31.   }
  32.   Title := "How many choices out of " . Cnt . "?"
  33.   Prompt := "Found " . Cnt . " items.`n`n"
  34.           . "How many to choose (1 - " . Cnt . ") ? "
  35.   InputBox, NChoices, % Title, % Prompt
  36.   If (ErrorLevel == 1)
  37.   {
  38.     OutputDebug, % "Canceled"
  39.     SoundBeep
  40.     Return
  41.   }
  42.   If (NChoices is not integer)
  43.   {
  44.     OutputDebug, % "Value not integer: " . NChoices
  45.     MsgBox, % "Please specify an integer (whole number)."
  46.     Return
  47.   }
  48.   If (NChoices <= 0) or (NChoices > Cnt)
  49.   {
  50.     OutputDebug, % "Value not between 1 and " . Cnt . ": " . NChoices
  51.     MsgBox, % "Please choose a number between 1 and " . Cnt . "."
  52.     Return
  53.   }
  54.   ResultStr := ""
  55.   Loop, % NChoices
  56.   {
  57.     MaxIndex := Lines.MaxIndex()
  58.     Random, Value, 1, % MaxIndex
  59.     ResultStr .= Lines[Value] . "`n"
  60.     Lines.Remove(Value)
  61.   }
  62.   Return ResultStr
  63. }

barney

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,282
    • View Profile
    • Donate to Member
Re: IDEA: Randomly select 'n' Lines from text list
« Reply #5 on: December 18, 2011, 12:10:18 PM »
With a bit of work i could make it so input could be done interactively.. but it's hard to justify if there are only 3 people on the planet who have any use for it.. seems like something that might be better done in modern times using an online web service..

Actually, I could see a use for this as an option in CHS, but that might be pretty specific to my usages.  Problem with Web services - apart from my paranoia - is that too many times I'm not, or unable to get, online.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,668
    • View Profile
    • Donate to Member
Re: IDEA: Randomly select 'n' Lines from text list
« Reply #6 on: December 18, 2011, 12:26:47 PM »
Give this a shot:  RandomLister

I wasn't sure if you wanted the results numbered sequentially or their actual line numbers from the source.

2011-12-18_122417.pngIDEA: Randomly select 'n' Lines from text list

magician62

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 118
    • View Profile
    • Donate to Member
Re: IDEA: Randomly select 'n' Lines from text list
« Reply #7 on: December 18, 2011, 03:53:19 PM »
skwire
The original concept was the results numbered sequentially, but as they appear on screen in order they are selected, its not necessary.

This meets the design requirement very well, many thanks.

ewemoa
I installed CHS and LAB, give me a month and I might have figured them out :)

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,668
    • View Profile
    • Donate to Member
Re: IDEA: Randomly select 'n' Lines from text list
« Reply #8 on: December 18, 2011, 04:21:21 PM »
This meets the design requirement very well, many thanks.

You're welcome.  That was more of a proof-of-concept i.e. it's not resizable and doesn't save any settings.  Did you want these bits added?

magician62

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 118
    • View Profile
    • Donate to Member
Re: IDEA: Randomly select 'n' Lines from text list
« Reply #9 on: December 18, 2011, 04:28:02 PM »
Not really necessary, as each usage would likely use a different data set.

Although resizing might be good for very large lists, its only really important to cases where the output is larger, and even then its not of major importance

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,668
    • View Profile
    • Donate to Member
Re: IDEA: Randomly select 'n' Lines from text list
« Reply #10 on: December 18, 2011, 06:00:16 PM »
Although resizing might be good for very large lists
Please download download RandomLister again.  The app should be resizable now.

magician62

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 118
    • View Profile
    • Donate to Member
Re: IDEA: Randomly select 'n' Lines from text list
« Reply #11 on: December 20, 2011, 03:30:11 PM »
Excellent!

Now using your telepathy, what is the next idea I have in mind for a simple utility? :)

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,668
    • View Profile
    • Donate to Member
Re: IDEA: Randomly select 'n' Lines from text list
« Reply #12 on: December 20, 2011, 03:35:00 PM »
Now using your telepathy, what is the next idea I have in mind for a simple utility?

An app to do all of your holiday shopping with gift-wrapping as an option?   :P

magician62

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 118
    • View Profile
    • Donate to Member
Re: IDEA: Randomly select 'n' Lines from text list
« Reply #13 on: December 20, 2011, 04:04:00 PM »
That would be brilliant, but you forgot the bit where it charges it to Santa's account, and not mine :)

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,668
    • View Profile
    • Donate to Member
Re: IDEA: Randomly select 'n' Lines from text list
« Reply #14 on: December 21, 2011, 10:04:54 AM »
That would be brilliant, but you forgot the bit where it charges it to Santa's account, and not mine :)

I'll add it to the ToDo list.  =]