Bug 15205

Summary: [patch] Addition to random(6)
Product: Base System Reporter: dalroi <dalroi>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 3.3-STABLE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description dalroi 1999-12-01 13:40:02 UTC
	The random command is not capable of what one would suspect it
	to do: printing one random line out of it's input.

	It can do so with numbers (random -e <denominator>), but not with lines
	of input.

Fix: The following patch adds the '-s' option to random, which prints one
	random line out of every <denominator> lines of input.

	Thus, "ls /bin | random -s 8" would result in, for example:
		chmod
		domainname
		pax
		stty

	(ls /bin results in 32 files on my system; 32/8 = 4 results)

	And "ls /bin | random -s $#" (invoked from a shell script) would result in one
	line from ls /bin.

	I use this for my random signature selector script. I suppose it has other
	uses.

How-To-Repeat: 
	not applicable
Comment 1 Kris Kennaway freebsd_committer freebsd_triage 2000-09-05 00:28:59 UTC
Responsible Changed
From-To: freebsd-bugs->billf

Billf takes care of stuff in /usr/games
Comment 2 jason-dated-1024524018.8d8c20 2002-06-11 23:00:18 UTC
Any reason why this patch was never applied?

--
(http://tmda.sourceforge.net/)
Comment 3 Mark Linimon freebsd_committer freebsd_triage 2007-03-14 23:02:35 UTC
State Changed
From-To: open->feedback

To submitter: does this patch still apply? 


Comment 4 Mark Linimon freebsd_committer freebsd_triage 2007-03-14 23:02:35 UTC
Responsible Changed
From-To: billf->linimon

Assignee did not respond to request for status of this PR, so reassign 
to the pool.
Comment 5 Mark Linimon freebsd_committer freebsd_triage 2007-03-14 23:38:36 UTC
State Changed
From-To: feedback->open

Submitter's email address bounces. 


Comment 6 Mark Linimon freebsd_committer freebsd_triage 2007-03-14 23:38:36 UTC
Responsible Changed
From-To: linimon->freebsd-bugs
Comment 7 SterlingCamden 2010-08-08 19:36:18 UTC
random(6) already does this, without the -s.  This should be closed.

-- 
Sterling (Chip) Camden    | sterling@camdensoftware.com | 2048D/3A978E4F
http://camdensoftware.com | http://chipstips.com        | http://chipsquips.com
Comment 8 Alexander Best freebsd_committer freebsd_triage 2010-08-10 03:39:58 UTC
could you provide an example how to reproduce the same output (ls /bin | random -s 8) with an unpatched copy of ranom?

cheers.
alex

-- 
a13x
Comment 9 Alexander Best freebsd_committer freebsd_triage 2010-08-10 10:55:04 UTC
On Mon Aug  9 10, Chip Camden wrote:
> Quoth Alexander Best on Tuesday, 10 August 2010:
> > could you provide an example how to reproduce the same output (ls /bin | random -s 8) with an unpatched copy of ranom?
> > 
> > cheers.
> > alex
> > 
> > -- 
> > a13x
> 
> 
> Sure:
> 
> ls /bin | random 8

i don't think this reproduces the exact ouput as `ls /bin | random -s 8`.

`random 8` will print each input line with a probability of 1/8th.

`random -s 8` on the other hand will print a random line out of every 8 lines of input. this means that for a static number of input lines `random -s 8` will always produce the same number of output lines, wheras the number of lines returned by `random 8` will be different for each run.

cheers
alex

ps: please keep bug-followup@ in the CC field so our conversation gets archived by GNATS.

> 
> -- 
> Sterling (Chip) Camden    | sterling@camdensoftware.com | 2048D/3A978E4F
> http://camdensoftware.com | http://chipstips.com        | http://chipsquips.com



-- 
a13x
Comment 10 olli 2010-08-10 11:00:22 UTC
Alexander Best <arundel@freebsd.org> wrote:
 >  could you provide an example how to reproduce the same output
 > (ls /bin | random -s 8) with an unpatched copy of ranom?

It's random, so it cannot be reproduced.  ;-)

But seriously ...  If you want random 4 lines out of 32
(or out of any number, for that matter), the following
command will do it:

$ ls /bin | random -f - | head -4

I agree that this PR can be closed.

Best regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd

"The ITU has offered the IETF formal alignment with its
corresponding technology, Penguins, but that won't fly."
        -- RFC 2549
Comment 11 Alexander Best freebsd_committer freebsd_triage 2010-08-10 11:11:27 UTC
On Tue Aug 10 10, Oliver Fromme wrote:
> Alexander Best <arundel@freebsd.org> wrote:
>  >  could you provide an example how to reproduce the same output
>  > (ls /bin | random -s 8) with an unpatched copy of ranom?
> 
> It's random, so it cannot be reproduced.  ;-)

*hehehe* i asume you know what i meant by that request.

> 
> But seriously ...  If you want random 4 lines out of 32
> (or out of any number, for that matter), the following
> command will do it:
> 
> $ ls /bin | random -f - | head -4

indeed this is an exact replacement for ls /bin | random -s 8.

> 
> I agree that this PR can be closed.

thanks a lot for clearing things up. i'll close the PR right away.

cheers.
alex

> 
> Best regards
>    Oliver
> 
> -- 
> Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
> Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
> secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
> chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart
> 
> FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd
> 
> "The ITU has offered the IETF formal alignment with its
> corresponding technology, Penguins, but that won't fly."
>         -- RFC 2549

-- 
a13x
Comment 12 Alexander Best freebsd_committer freebsd_triage 2010-08-10 11:11:44 UTC
State Changed
From-To: open->closed

The functionality that is being provided by the patch can be reproduced by 
ls /bin | random -f -|head -n X (X being the number of random lines that should 
be generated). 
Due to this matter and the fact that the patch didn't trigger a lot of interest 
in more than 10 years I'm closing this PR.
Comment 13 olli 2010-08-10 12:06:49 UTC
Alexander Best wrote:
 > On Tue Aug 10 10, Oliver Fromme wrote:
 > > But seriously ...  If you want random 4 lines out of 32
 > > (or out of any number, for that matter), the following
 > > command will do it:
 > > 
 > > $ ls /bin | random -f - | head -4
 > 
 > indeed this is an exact replacement for ls /bin | random -s 8.

In fact it's a _better_ replacement because the probability
is evenly distributed across the whole input.  This is not
the case for the patch proposed in this PR.

 > > I agree that this PR can be closed.
 > 
 > thanks a lot for clearing things up. i'll close the PR right away.

Thanks!

Best regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd

"Whatever happened to the days when hacking started
at the cerebral cortex, and not at the keyboard?"
  --  Sid on userfriendly.org by Illiad, 2007-06-20
Comment 14 SterlingCamden 2010-08-10 16:26:23 UTC
Quoth Alexander Best on Tuesday, 10 August 2010:
> On Mon Aug  9 10, Chip Camden wrote:
> > Quoth Alexander Best on Tuesday, 10 August 2010:
> > > could you provide an example how to reproduce the same output (ls /bin | random -s 8) with an unpatched copy of ranom?
> > > 
> > > cheers.
> > > alex
> > > 
> > > -- 
> > > a13x
> > 
> > 
> > Sure:
> > 
> > ls /bin | random 8
> 
> i don't think this reproduces the exact ouput as `ls /bin | random -s 8`.
> 
> `random 8` will print each input line with a probability of 1/8th.
> 
> `random -s 8` on the other hand will print a random line out of every 8 lines of input. this means that for a static number of input lines `random -s 8` will always produce the same number of output lines, wheras the number of lines returned by `random 8` will be different for each run.
> 
> cheers
> alex
> 
> ps: please keep bug-followup@ in the CC field so our conversation gets archived by GNATS.
> 
> > 
> > -- 
> > Sterling (Chip) Camden    | sterling@camdensoftware.com | 2048D/3A978E4F
> > http://camdensoftware.com | http://chipstips.com        | http://chipsquips.com
> 
> 

Ah, you are correct.  I missed that subtle difference.
> 
> -- 
> a13x


-- 
Sterling (Chip) Camden    | sterling@camdensoftware.com | 2048D/3A978E4F
http://camdensoftware.com | http://chipstips.com        | http://chipsquips.com