Re: Bug#822221: ITP: flipcoin -- flip an adjustable coin for random exit status

2016-04-22 Thread Guus Sliepen
On Fri, Apr 22, 2016 at 02:45:59PM +0200, Jakub Wilk wrote:

> > fp = fopen("/dev/urandom", "rb");
> > if (fp == NULL) {
> >   fprintf(stderr, "Error: Cannot open /dev/urandom.\n");
> 
> The error message doesn't say what the error was, or what program caused
> this error.

While we are at it, instead of opening /dev/urandom, use the getrandom()
function if it's available. The latter has more chance of working in
chroots that don't have a /dev.

-- 
Met vriendelijke groet / with kind regards,
  Guus Sliepen 


signature.asc
Description: Digital signature


Re: Bug#822221: ITP: flipcoin -- flip an adjustable coin for random exit status

2016-04-22 Thread Carlos Alberto Lopez Perez
On 22/04/16 14:48, Adam Borowski wrote:
> On Thu, Apr 21, 2016 at 11:11:39PM -0700, Rudi Cilibrasi wrote:
>> * Package name: flipcoin
>> * URL : https://github.com/rudi-cilibrasi/flipcoin
>>   Description : flip an adjustable coin for random exit status
>>
>> This command-line utility can be used to simulate a coin flip to get
>> a random exit status.  The probability of success is adjustable using
>> an optional command line parameter.
> [...]
>> This package is a useful core utility for shell scripts that need to
>> do things in a way that is decorrelated in time and infrequent. Usage is
>> simple at the shell prompt:
>>
>> if flipcoin ; then echo heads ; else echo tails ; fi
> 
> Sorry, but I don't believe that someone writing shell scripts is likely to
> not know one of many ways to do this, be it $RANDOM, perl, awk, or, if you
> really want to require something non-essential, rolldice.
> 
> Thus, please reconsider the point of packaging this.
> 
> 
> Meow!
>
Indeed. With bash:

flipcoin() { return $(($RANDOM % 2)); }

if flipcoin ; then echo heads ; else echo tails ; fi

:)



signature.asc
Description: OpenPGP digital signature


Re: Bug#822221: ITP: flipcoin -- flip an adjustable coin for random exit status

2016-04-22 Thread Jakub Wilk

* Anthony DeRobertis , 2016-04-22, 09:09:

memset(, 0xff, sizeof(maxInt));

"maxInt = -1" is would be a more obvious way to write it, IMHO.

Both pale in comparison to UINT32_MAX, also found in .


Meh. The advantage of the existing code is that it doesn't repeat the 
size of valInt/maxInt anywhere. If you were going to give op on this 
nice property, you might as well get rid of maxInt completely, and 
instead of:


((double) maxInt)+1.0

write:

0x1P32



Re: Bug#822221: ITP: flipcoin -- flip an adjustable coin for random exit status

2016-04-22 Thread Anthony DeRobertis

On 04/22/2016 08:45 AM, Jakub Wilk wrote:



 memset(, 0xff, sizeof(maxInt));


"maxInt = -1" is would be a more obvious way to write it, IMHO.


Both pale in comparison to UINT32_MAX, also found in .



Re: Bug#822221: ITP: flipcoin -- flip an adjustable coin for random exit status

2016-04-22 Thread Adam Borowski
On Thu, Apr 21, 2016 at 11:11:39PM -0700, Rudi Cilibrasi wrote:
> * Package name: flipcoin
> * URL : https://github.com/rudi-cilibrasi/flipcoin
>   Description : flip an adjustable coin for random exit status
> 
> This command-line utility can be used to simulate a coin flip to get
> a random exit status.  The probability of success is adjustable using
> an optional command line parameter.
[...]
> This package is a useful core utility for shell scripts that need to
> do things in a way that is decorrelated in time and infrequent. Usage is
> simple at the shell prompt:
> 
> if flipcoin ; then echo heads ; else echo tails ; fi

Sorry, but I don't believe that someone writing shell scripts is likely to
not know one of many ways to do this, be it $RANDOM, perl, awk, or, if you
really want to require something non-essential, rolldice.

Thus, please reconsider the point of packaging this.


Meow!
-- 
A tit a day keeps the vet away.



Re: Bug#822221: ITP: flipcoin -- flip an adjustable coin for random exit status

2016-04-22 Thread Jakub Wilk

Hi Rudi!

[When filing a bug, please use X-Debbugs-CC instead of plain CC, so that 
the copied person (or list) receives the message with bug number from 
the BTS.]


* Rudi Cilibrasi , 2016-04-21, 23:11:

* Package name: flipcoin
 Version : 1.0.0
 Upstream Author : Rudi Cilibrasi 
* URL : https://github.com/rudi-cilibrasi/flipcoin


Um, this page says "0 releases". Has 1.0.0 actually been released?

I'm an enthusiast of small programs that do one thing well. But I'd 
expect a program which is that short to be perfectly polished, and this 
one is not. Here's my review of this code:



 if (argc > 1)
   probability = atof(argv[1]);


No error handling... I'd expect to see an error message when the 
probability cannot be parsed, or it is out of range would be helpful, or 
there are too many arguments.



 memset(, 0xff, sizeof(maxInt));


"maxInt = -1" is would be a more obvious way to write it, IMHO.


 fp = fopen("/dev/urandom", "rb");
 if (fp == NULL) {
   fprintf(stderr, "Error: Cannot open /dev/urandom.\n");


The error message doesn't say what the error was, or what program 
caused this error.



   exit(2);


This exit code should be documented in the manpage.


 if (fread(, 1, sizeof(valInt), fp) != sizeof(valInt)) {
   fprintf(stderr, "Error: Cannot read from /dev/urandom.\n");
   exit(2);


Same problems are above.


 return ((probability * ((double) maxInt)+1.0) < valInt);


This is off-by-one, making the return value slightly biased towards 0.

Both COPYING and LICENSE exist and they are identical. Surely one would 
be enough? :-)


There is no test suite...

All in all, I don't think this is mature enough to be uploaded to Debian 
at this time.


--
Jakub Wilk



ITP: flipcoin -- flip an adjustable coin for random exit status

2016-04-22 Thread Rudi Cilibrasi

Package: wnpp
Severity: wishlist
Owner: Rudi Cilibrasi 

* Package name: flipcoin
  Version : 1.0.0
  Upstream Author : Rudi Cilibrasi 
* URL : https://github.com/rudi-cilibrasi/flipcoin
* License : MIT/X
  Programming Lang: C
  Description : flip an adjustable coin for random exit status

This command-line utility can be used to simulate a coin flip to get
a random exit status.  The probability of success is adjustable using
an optional command line parameter.

The package includes a single binary executable and man page and is
easily buildable using autoconf and automake.

Although I was a Debian Developer ten years ago, I have not had time to
do much since having kids. I am hoping somebody else can take this
package and sign and upload it. I do not expect to make many revisions
because the source code and functionality are quite simple so the
maintenance burden should be almost zero in the future. I would
appreciate an adoption, co-maintainer, or sponsor as appropriate.

For your convenience, an initial lintian-clean Debian source package is
publicly available at:

https://github.com/rudi-cilibrasi/pkg-flipcoin

This package is a useful core utility for shell scripts that need to
do things in a way that is decorrelated in time and infrequent. Usage is
simple at the shell prompt:

if flipcoin ; then echo heads ; else echo tails ; fi