Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #147714
| From | James Kuyper <jameskuyper@alumni.caltech.edu> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Bart, a tcc "issue" |
| Date | 2019-11-07 10:05 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <qq1br5$3o1$1@dont-email.me> (permalink) |
| References | <uRIwF.17878$kE3.891@fx36.iad> |
On 11/6/19 6:40 PM, DFS wrote:
> I wrote a distribution of characters counter, and on tcc (0.9.26) on
> Windows it always undercounts the last character in the set (9). If you
> have tcc on Windows maybe you could test it. Doesn't happen on
> gcc/MSYS2/Windows.
>
> 6 = 16258
> 7 = 16177
> 8 = 16068
> 9 = 14980
>
> 6 = 16134
> 7 = 15964
> 8 = 16144
> 9 = 15074
>
> 6 = 16074
> 7 = 16123
> 8 = 16132
> 9 = 15304
>
> 6 = 16180
> 7 = 16083
> 8 = 16337
> 9 = 15149
>
> 6 = 16126
> 7 = 16162
> 8 = 16138
> 9 = 15271
>
> 6 = 16116
> 7 = 16043
> 8 = 15987
> 9 = 15056
>
> =====================================================================
> #include <stdlib.h>
> #include <stdio.h>
> #include <time.h>
> #include <math.h>
> #include <string.h>
>
> int randNbr(int low, int high) {
> return (low + rand() / (RAND_MAX / (high - low + 1) + 1));
> }
>
> int main(void) {
>
> int i=0,j=0,k=0,cnt=0;
>
> srand(time(NULL));
>
> char charset[63] =
> "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
> int charsetLen = strlen(charset);
> printf("n = 1000000\n");
> for(i=0;i<charsetLen;i++) {
> for(j=0;j<1000000;j++) {
Note: conforming implementations of C can have INT_MAX < 1000000. For
portable code, I'd recommend declaring j to be int_fast32_t or long,
rather than int.
> k = randNbr(0,charsetLen-1);
> if(charset[i] == charset[k]) {cnt++;}
That if-condition throws away roughly 61 out of 62 of the random numbers
you generate. See below for a more efficient approach.
> }
> printf("%c = %d\n",charset[i],cnt);
> cnt=0;
> }
> exit(0);> }
int main(void)
{
const char charset[] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789";
#define CHARS (sizeof charset - 1)
int cnt[CHARS]={0};
for(int_fast32_t j=0; j<1000000; j++)
cnt[randNbr(0, CHARS)]++;
for(int i=0; i<CHARS; i++)
printf("%c: %d\n", charset[i], cnt[i]);
return 0;
}
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Bart, a tcc "issue" DFS <nospam@dfs.com> - 2019-11-06 18:40 -0500
Re: Bart, a tcc "issue" Bart <bc@freeuk.com> - 2019-11-07 00:03 +0000
Re: Bart, a tcc "issue" Bart <bc@freeuk.com> - 2019-11-07 00:06 +0000
Re: Bart, a tcc "issue" Bart <bc@freeuk.com> - 2019-11-07 01:44 +0000
Re: Bart, a tcc "issue" James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-11-07 10:05 -0500
Re: Bart, a tcc "issue" DFS <nospam@dfs.com> - 2019-11-07 13:22 -0500
Re: Bart, a tcc "issue" DFS <nospam@dfs.com> - 2019-11-08 09:19 -0500
Re: Bart, a tcc "issue" James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-11-08 11:03 -0500
Re: Bart, a tcc "issue" Manfred <noname@add.invalid> - 2019-11-07 18:22 +0100
Re: Bart, a tcc "issue" Manfred <noname@add.invalid> - 2019-11-07 18:30 +0100
Re: Bart, a tcc "issue" Richard Damon <Richard@Damon-Family.org> - 2019-11-08 20:51 -0500
Re: Bart, a tcc "issue" Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-11-08 20:59 -0800
Re: Bart, a tcc "issue" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-09 23:16 +0000
Re: Bart, a tcc "issue" Richard Damon <Richard@Damon-Family.org> - 2019-11-09 20:27 -0500
Re: Bart, a tcc "issue" Bart <bc@freeuk.com> - 2019-11-10 01:38 +0000
Re: Bart, a tcc "issue" Richard Damon <Richard@Damon-Family.org> - 2019-11-09 20:59 -0500
Re: Bart, a tcc "issue" Keith Thompson <kst-u@mib.org> - 2019-11-09 19:22 -0800
Re: Bart, a tcc "issue" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-10 03:04 +0000
Re: Bart, a tcc "issue" Richard Damon <Richard@Damon-Family.org> - 2019-11-09 23:04 -0500
Re: Bart, a tcc "issue" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-10 13:15 +0000
Re: Bart, a tcc "issue" Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-11-10 06:04 -0800
Re: Bart, a tcc "issue" Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-11-10 07:49 -0800
Re: Bart, a tcc "issue" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-10 17:49 +0000
Re: Bart, a tcc "issue" "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-11-11 02:44 -0800
Re: Bart, a tcc "issue" James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-11-11 13:57 -0500
Re: Bart, a tcc "issue" "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-11-14 16:51 -0800
Re: Bart, a tcc "issue" Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-11-28 16:03 -0800
csiph-web