diff options
author | Christian Neukirchen <chneukirchen@gmail.com> | 2016-01-22 18:43:14 +0100 |
---|---|---|
committer | Christian Neukirchen <chneukirchen@gmail.com> | 2016-01-22 18:43:14 +0100 |
commit | 372fdabc1fcb5eda5a90a05da3d9f9b3b5857ba5 (patch) | |
tree | 6bb3109b362610f3024cff3e42a946d154737f20 /src/usr.bin/jot | |
parent | 193f150ac3a87fad164b3911bb69280b0728f6f1 (diff) | |
download | outils-372fdabc1fcb5eda5a90a05da3d9f9b3b5857ba5.tar.gz outils-372fdabc1fcb5eda5a90a05da3d9f9b3b5857ba5.tar.xz outils-372fdabc1fcb5eda5a90a05da3d9f9b3b5857ba5.zip |
cvs update
Diffstat (limited to 'src/usr.bin/jot')
-rw-r--r-- | src/usr.bin/jot/Makefile | 4 | ||||
-rw-r--r-- | src/usr.bin/jot/jot.1 | 11 | ||||
-rw-r--r-- | src/usr.bin/jot/jot.c | 44 |
3 files changed, 52 insertions, 7 deletions
diff --git a/src/usr.bin/jot/Makefile b/src/usr.bin/jot/Makefile index c552df3..3498301 100644 --- a/src/usr.bin/jot/Makefile +++ b/src/usr.bin/jot/Makefile @@ -1,6 +1,8 @@ -# $OpenBSD: Makefile,v 1.4 2003/12/29 08:51:19 otto Exp $ +# $OpenBSD: Makefile,v 1.5 2016/01/10 01:15:52 tb Exp $ PROG= jot CFLAGS+= -Wall +LDADD+= -lm +DPADD+= ${LIBM} .include <bsd.prog.mk> diff --git a/src/usr.bin/jot/jot.1 b/src/usr.bin/jot/jot.1 index 9845fa3..7bd0675 100644 --- a/src/usr.bin/jot/jot.1 +++ b/src/usr.bin/jot/jot.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: jot.1,v 1.18 2014/01/20 05:07:48 schwarze Exp $ +.\" $OpenBSD: jot.1,v 1.19 2016/01/04 23:21:28 schwarze Exp $ .\" $NetBSD: jot.1,v 1.2 1994/11/14 20:27:36 jtc Exp $ .\" .\" Copyright (c) 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)jot.1 8.1 (Berkeley) 6/6/93 .\" -.Dd $Mdocdate: January 20 2014 $ +.Dd $Mdocdate: January 4 2016 $ .Dt JOT 1 .Os .Sh NAME @@ -313,3 +313,10 @@ To print all lines 80 characters or longer: .Xr yes 1 , .Xr arc4random 3 , .Xr printf 3 +.Sh HISTORY +The +.Nm +utility first appeared in +.Bx 4.2 . +.Sh AUTHORS +.An John A. Kunze diff --git a/src/usr.bin/jot/jot.c b/src/usr.bin/jot/jot.c index 8952ead..e4fdade 100644 --- a/src/usr.bin/jot/jot.c +++ b/src/usr.bin/jot/jot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: jot.c,v 1.26 2015/10/09 01:37:07 deraadt Exp $ */ +/* $OpenBSD: jot.c,v 1.27 2016/01/10 01:15:52 tb Exp $ */ /* $NetBSD: jot.c,v 1.3 1994/12/02 20:29:43 pk Exp $ */ /*- @@ -40,6 +40,8 @@ #include <stdbool.h> #include <ctype.h> #include <limits.h> +#include <math.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -268,11 +270,45 @@ main(int argc, char *argv[]) if (reps == 0) infinity = true; if (randomize) { - x = (ender - begin) * (ender > begin ? 1 : -1); + bool use_unif; + uint32_t pow10 = 1; + uint32_t uintx = 0; /* Initialized to make gcc happy. */ + + if (prec > 9) /* pow(10, prec) > UINT32_MAX */ + errx(1, "requested precision too large"); + + while (prec-- > 0) + pow10 *= 10; + + if (ender < begin) { + x = begin; + begin = ender; + ender = x; + } + x = ender - begin; + + /* + * If pow10 * (ender - begin) is an integer, use + * arc4random_uniform(). + */ + use_unif = fmod(pow10 * (ender - begin), 1) == 0; + if (use_unif) { + uintx = pow10 * (ender - begin); + if (uintx >= UINT32_MAX) + errx(1, "requested range too large"); + uintx++; + } + for (i = 1; i <= reps || infinity; i++) { double v; - y = arc4random() / ((double)0xffffffff + 1); - v = y * x + begin; + + if (use_unif) { + y = arc4random_uniform(uintx) / (double)pow10; + v = y + begin; + } else { + y = arc4random() / ((double)0xffffffff + 1); + v = y * x + begin; + } if (putdata(v, reps == i && !infinity)) errx(1, "range error in conversion: %f", v); } |