FreeBSD Bugzilla – Attachment 6830 Details for
Bug 15205
[patch] Addition to random(6)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
file.diff
file.diff (text/plain), 3.83 KB, created by
dalroi
on 1999-12-01 13:40:02 UTC
(
hide
)
Description:
file.diff
Filename:
MIME Type:
Creator:
dalroi
Created:
1999-12-01 13:40:02 UTC
Size:
3.83 KB
patch
obsolete
>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); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 15205
: 6830