From dalroi@wit401310.student.utwente.nl Wed Dec  1 04:28:08 1999
Return-Path: <dalroi@wit401310.student.utwente.nl>
Received: from wit401310.student.utwente.nl (wit401310.student.utwente.nl [130.89.236.150])
	by hub.freebsd.org (Postfix) with ESMTP id 8316514CFB
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  1 Dec 1999 04:28:03 -0800 (PST)
	(envelope-from dalroi@wit401310.student.utwente.nl)
Received: by wit401310.student.utwente.nl (Postfix, from userid 1001)
	id D48BA1EE3; Wed,  1 Dec 1999 13:28:13 +0100 (CET)
Message-Id: <19991201122813.D48BA1EE3@wit401310.student.utwente.nl>
Date: Wed,  1 Dec 1999 13:28:13 +0100 (CET)
From: dalroi@wit401310.student.utwente.nl
Reply-To: dalroi@wit401310.student.utwente.nl
To: FreeBSD-gnats-submit@freebsd.org
Subject: Addition to /usr/games/random
X-Send-Pr-Version: 3.2

>Number:         15205
>Category:       bin
>Synopsis:       [patch] Addition to random(6)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec  1 05:40:02 PST 1999
>Closed-Date:    Tue Aug 10 10:22:06 UTC 2010
>Last-Modified:  Tue Aug 10 15:30:04 UTC 2010
>Originator:     Alban Hertroys
>Release:        FreeBSD 3.3-STABLE i386
>Organization:
>Environment:

	FreeBSD 3.3-STABLE, i386

>Description:

	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.

>How-To-Repeat:

	not applicable

>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.


diff -c games/random.orig/random.6 games/random/random.6
*** games/random.orig/random.6	Mon Nov 29 20:09:59 1999
--- games/random/random.6	Mon Nov 29 20:09:01 1999
***************
*** 39,45 ****
  .Nd random lines from a file or random numbers
  .Sh SYNOPSIS
  .Nm random
! .Op Fl er
  .Op Ar denominator
  .Sh DESCRIPTION
  .Nm Random
--- 39,45 ----
  .Nd random lines from a file or random numbers
  .Sh SYNOPSIS
  .Nm random
! .Op Fl esr
  .Op Ar denominator
  .Sh DESCRIPTION
  .Nm Random
***************
*** 60,65 ****
--- 60,73 ----
  exit value of 0 to
  .Ar denominator
  \&- 1, inclusive.
+ .It Fl s
+ If the
+ .Fl s
+ option is specified, 
+ .Nm random
+ copies one random line out of every 
+ .Ar denominator
+ lines to stdout, instead.
  .It Fl r
  The
  .Fl r
diff -c games/random.orig/random.c games/random/random.c
*** games/random.orig/random.c	Mon Nov 29 19:26:29 1999
--- games/random/random.c	Mon Nov 29 20:03:20 1999
***************
*** 63,73 ****
  {
  	extern int optind;
  	double denom;
! 	int ch, random_exit, selected, unbuffer_output;
  	char *ep;
  
! 	random_exit = unbuffer_output = 0;
! 	while ((ch = getopt(argc, argv, "er")) != -1)
  		switch (ch) {
  		case 'e':
  			random_exit = 1;
--- 63,73 ----
  {
  	extern int optind;
  	double denom;
! 	int ch, random_exit, selected, unbuffer_output, random_select, index;
  	char *ep;
  
! 	random_exit = unbuffer_output = random_select = 0;
! 	while ((ch = getopt(argc, argv, "esr")) != -1)
  		switch (ch) {
  		case 'e':
  			random_exit = 1;
***************
*** 75,80 ****
--- 75,83 ----
  		case 'r':
  			unbuffer_output = 1;
  			break;
+ 		case 's':
+ 			random_select = 1;
+ 			break;
  		default:
  		case '?':
  			usage();
***************
*** 116,138 ****
  	if (unbuffer_output)
  		setbuf(stdout, NULL);
  
  	/*
  	 * Select whether to print the first line.  (Prime the pump.)
  	 * We find a random number between 0 and denom - 1 and, if it's
  	 * 0 (which has a 1 / denom chance of being true), we select the
  	 * line.
  	 */
! 	selected = (int)(denom * random() / LONG_MAX) == 0;
! 	while ((ch = getchar()) != EOF) {
! 		if (selected)
! 			(void)putchar(ch);
! 		if (ch == '\n') {
! 			/* End of that line.  See if we got an error. */
! 			if (ferror(stdout))
! 				err(2, "stdout");
! 
! 			/* Now see if the next line is to be printed. */
! 			selected = (int)(denom * random() / LONG_MAX) == 0;
  		}
  	}
  	if (ferror(stdin))
--- 119,164 ----
  	if (unbuffer_output)
  		setbuf(stdout, NULL);
  
+ 	if (random_select == 0) {
  	/*
  	 * Select whether to print the first line.  (Prime the pump.)
  	 * We find a random number between 0 and denom - 1 and, if it's
  	 * 0 (which has a 1 / denom chance of being true), we select the
  	 * line.
  	 */
! 		selected = (int)(denom * random() / LONG_MAX) == 0;
! 		while ((ch = getchar()) != EOF) {
! 			if (selected)
! 				(void)putchar(ch);
! 			if (ch == '\n') {
! 				/* End of that line.  See if we got an error. */
! 				if (ferror(stdout))
! 					err(2, "stdout");
! 	
! 				/* Now see if the next line is to be printed. */
! 				selected = (int)(denom * random() / LONG_MAX) == 0;
! 			}
! 		}
! 	} else {
! 	/*
! 	 * Print one random line out of every denom lines.
! 	 */
! 		selected = (int)(denom * random() / LONG_MAX);
! 		index = 0;
! 		while ((ch = getchar()) != EOF) {
! 			if (selected == index)
! 				(void)putchar(ch);
! 			if (ch == '\n') {
! 				/* End of that line. See if we got an error. */
! 				if (ferror(stdout))
! 					err(2,"stdout");
! 
! 				index++;
! 				if (index >= denom) {
! 					index = 0;
! 					selected = (int)(denom * random() / LONG_MAX);
! 				}
! 			}
  		}
  	}
  	if (ferror(stdin))
***************
*** 144,149 ****
  usage()
  {
  
! 	(void)fprintf(stderr, "usage: random [-er] [denominator]\n");
  	exit(1);
  }
--- 170,175 ----
  usage()
  {
  
! 	(void)fprintf(stderr, "usage: random [-esr] [denominator]\n");
  	exit(1);
  }


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->billf 
Responsible-Changed-By: kris 
Responsible-Changed-When: Mon Sep 4 16:28:59 PDT 2000 
Responsible-Changed-Why:  
Billf takes care of stuff in /usr/games 

http://www.freebsd.org/cgi/query-pr.cgi?pr=15205 

From: "Jason R. Mastaler" <jason-dated-1024524018.8d8c20@mastaler.com>
To: freebsd-gnats-submit@FreeBSD.org
Cc: dalroi@wit401310.student.utwente.nl
Subject: Re: misc/15205: Addition to /usr/games/random
Date: Wed, 12 Jun 2002 00:00:18 +0200 (CAT)

 Any reason why this patch was never applied?
 
 --
 (http://tmda.sourceforge.net/)
State-Changed-From-To: open->feedback 
State-Changed-By: linimon 
State-Changed-When: Wed Mar 14 23:02:35 UTC 2007 
State-Changed-Why:  
To submitter: does this patch still apply? 


Responsible-Changed-From-To: billf->linimon 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Wed Mar 14 23:02:35 UTC 2007 
Responsible-Changed-Why:  
Assignee did not respond to request for status of this PR, so reassign 
to the pool. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=15205 
State-Changed-From-To: feedback->open 
State-Changed-By: linimon 
State-Changed-When: Wed Mar 14 23:38:36 UTC 2007 
State-Changed-Why:  
Submitter's email address bounces. 


Responsible-Changed-From-To: linimon->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Wed Mar 14 23:38:36 UTC 2007 
Responsible-Changed-Why:  

http://www.freebsd.org/cgi/query-pr.cgi?pr=15205 

From: Chip Camden <sterling@camdensoftware.com>
To: bug-followup@FreeBSD.org, dalroi@wit401310.student.utwente.nl
Cc:  
Subject: Re: bin/15205: [patch] Addition to random(6)
Date: Sun, 8 Aug 2010 11:36:18 -0700

 --gKMricLos+KVdGMg
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 random(6) already does this, without the -s.  This should be closed.
 
 --=20
 Sterling (Chip) Camden    | sterling@camdensoftware.com | 2048D/3A978E4F
 http://camdensoftware.com | http://chipstips.com        | http://chipsquips=
 .com
 
 --gKMricLos+KVdGMg
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.10 (FreeBSD)
 
 iQEcBAEBAgAGBQJMXvkhAAoJEIpckszW26+RmpAIALNUafB80t4qZIgwvJomLVyc
 HmJj28n66gy6/Mpkj6CO4vkBzBUnu74kB4v3xAwOW5UwSjraWNpV+TjO6vEmg1hl
 l/gdQIrIQ7gt3q8PdxgxwBRSzYETyHFeOzTxQu+dnDVgL9mNXnYGB/0W86DMa8Ad
 BQpWeLNF82SyUAEWH4eBckIeA4Fw8/kSsKbqiubG6HTtPKazr/OmHQjVuAvm/P6i
 5GiGu1RF5VcXnCfqqaLwh56LutdVVKUVvdMOZn+oCJcFFw/JRUjqCEygnXT7V2IK
 wtedwunerwTsu9LGUTC3Pb4XhSaARxQEsZ2eyzqh5zoryMQ8OARCPTzQ5XFc95s=
 =Ym/H
 -----END PGP SIGNATURE-----
 
 --gKMricLos+KVdGMg--

From: Alexander Best <arundel@freebsd.org>
To: bug-followup@freebsd.org
Cc: Chip Camden <sterling@camdensoftware.com>
Subject: Re: bin/15205: [patch] Addition to random(6)
Date: Tue, 10 Aug 2010 02:39:58 +0000

 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

From: Alexander Best <arundel@freebsd.org>
To: Chip Camden <sterling@camdensoftware.com>
Cc: bug-followup@freebsd.org
Subject: Re: bin/15205: [patch] Addition to random(6)
Date: Tue, 10 Aug 2010 09:55:04 +0000

 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

From: Oliver Fromme <olli@lurza.secnetix.de>
To: freebsd-bugs@FreeBSD.ORG, bug-followup@FreeBSD.ORG,
        Alexander Best <arundel@FreeBSD.ORG>
Cc:  
Subject: Re: bin/15205: [patch] Addition to random(6)
Date: Tue, 10 Aug 2010 12:00:22 +0200 (CEST)

 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,  Geschftsfuehrung:
 secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mn-
 chen, HRB 125758,  Geschftsfhrer: 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
State-Changed-From-To: open->closed 
State-Changed-By: arundel 
State-Changed-When: Tue Aug 10 10:11:44 UTC 2010 
State-Changed-Why:  
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. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=15205 

From: Alexander Best <arundel@freebsd.org>
To: Chip Camden <sterling@camdensoftware.com>,
	Oliver Fromme <olli@lurza.secnetix.de>
Cc: bug-followup@freebsd.org
Subject: Re: bin/15205: [patch] Addition to random(6)
Date: Tue, 10 Aug 2010 10:11:27 +0000

 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,  Geschftsfuehrung:
 > secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mn-
 > chen, HRB 125758,  Geschftsfhrer: 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

From: Oliver Fromme <olli@lurza.secnetix.de>
To: arundel@FreeBSD.ORG (Alexander Best)
Cc: sterling@camdensoftware.com (Chip Camden), bug-followup@FreeBSD.ORG
Subject: Re: bin/15205: [patch] Addition to random(6)
Date: Tue, 10 Aug 2010 13:06:49 +0200 (CEST)

 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,  Geschftsfuehrung:
 secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mn-
 chen, HRB 125758,  Geschftsfhrer: 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

From: Chip Camden <sterling@camdensoftware.com>
To: Alexander Best <arundel@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: bin/15205: [patch] Addition to random(6)
Date: Tue, 10 Aug 2010 08:26:23 -0700

 --ftEhullJWpWg/VHq
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 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 /bi=
 n | random -s 8) with an unpatched copy of ranom?
 > > >=20
 > > > cheers.
 > > > alex
 > > >=20
 > > > --=20
 > > > a13x
 > >=20
 > >=20
 > > Sure:
 > >=20
 > > ls /bin | random 8
 >=20
 > i don't think this reproduces the exact ouput as `ls /bin | random -s 8`.
 >=20
 > `random 8` will print each input line with a probability of 1/8th.
 >=20
 > `random -s 8` on the other hand will print a random line out of every 8 l=
 ines 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.
 >=20
 > cheers
 > alex
 >=20
 > ps: please keep bug-followup@ in the CC field so our conversation gets ar=
 chived by GNATS.
 >=20
 > >=20
 > > --=20
 > > Sterling (Chip) Camden    | sterling@camdensoftware.com | 2048D/3A978E4F
 > > http://camdensoftware.com | http://chipstips.com        | http://chipsq=
 uips.com
 >=20
 >=20
 Ah, you are correct.  I missed that subtle difference.
 >=20
 > --=20
 > a13x
 
 --=20
 Sterling (Chip) Camden    | sterling@camdensoftware.com | 2048D/3A978E4F
 http://camdensoftware.com | http://chipstips.com        | http://chipsquips=
 .com
 
 --ftEhullJWpWg/VHq
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.10 (FreeBSD)
 
 iQEcBAEBAgAGBQJMYW+fAAoJEIpckszW26+RMAkH/13LNyxpAtYxqk2N2Fl+hSfe
 t19KEgCc8v7je7J/V6Ok5YjKvOd5055NcybBZ50xtsEhgokOcchBDqoCERPtBDKW
 fGWr5PTgYzZ6HtjAM5/44Uy3JR3iQvb+aRJiYIdqrVsWyZ53YktApr5fdBe5w9jh
 4GiIQUsvcOzKVN4OWooJgyZWCVf9En2kwL6xK0TmR8EQLpcZWvgCAdHeC8EhzMz1
 fRTCEKTIkaXJLO8CEPepPsowE1/AX+kyRAILcWqNR/4NNkZMXiA9Y/Csf5OFiAfJ
 tLNk1GnKxKapgUyAxaxr2kM6OU8tjeSuy8mePbwGP3UnsVfYwoS9LiPf6CRcsjo=
 =o/4t
 -----END PGP SIGNATURE-----
 
 --ftEhullJWpWg/VHq--
>Unformatted:
