Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Subject | Re: What are the odds? |
|---|---|
| Newsgroups | sci.math |
| References | <hxrwF.14017$2A5.601@fx38.iad> <d3d5se5l55l6abkkm0ja75scmepgsr4p03@4ax.com> |
| From | DFS <nospam@dfs.com> |
| Message-ID | <fQBwF.59470$Ko9.7309@fx48.iad> (permalink) |
| Organization | blocknews - www.blocknews.net |
| Date | 2019-11-06 10:40 -0500 |
On 11/6/2019 7:13 AM, Barry Schwarz wrote:
> On Tue, 5 Nov 2019 22:57:55 -0500, DFS <nospam@dfs.com> wrote:
>
>> I wrote a program to generate S random strings of length L to H
>>
>> $randoms S L H
>> $randoms 1000 4 6
>>
>> generates 1000 random strings of length 4 to 6
>>
>> The character set it randomly chooses from is your standard:
>> "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
>>
>> I ran it recently for 1000 2 4, and one of the strings it returned was
>> 'RUN'. all uppercase.
>>
>> So my question is: What are the odds that all uppercase RUN would be
>> "chosen" in a set of 1000 tries, with a length of 2, 3 or 4, from that
>> 62-item character set?
>
> There are two different problems here. One is the probability of RUN
> occurring in a string of 3 characters which James has discussed. The
> other is the probability that your generator will generate a string of
> 3 rather than 2 or 4. You have not told us anything about that.
>>
>> I know the fact that it's a real word is irrelevant to the odds.
>>
>> Naively I would guess the odds are: 1/62 * 1/62 * 1/62 * 1/3
>
> That 1/3 implies that each string length is equally likely.
Then the 1/62 also implies that each letter choice is equally likely.
> Is that really the case?
I don't know. The distribution results below don't look that great to me.
$ ./dist
n = 10
Count of 2 = 4
Count of 3 = 4
Count of 4 = 2
n = 100
Count of 2 = 35
Count of 3 = 36
Count of 4 = 29
n = 1000
Count of 2 = 331
Count of 3 = 335
Count of 4 = 334
n = 10000
Count of 2 = 3357
Count of 3 = 3379
Count of 4 = 3264
n = 100000
Count of 2 = 33151
Count of 3 = 33323
Count of 4 = 33526
n = 1000000
Count of 2 = 332574
Count of 3 = 333870
Count of 4 = 333556
n = 10000000
Count of 2 = 3333772
Count of 3 = 3335493
Count of 4 = 3330735
---------------------------------------------------------------------------
#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;
int cnt=0,cnt2=0,cnt3=0,cnt4=0;
double x=10.0, y=0.0;
srand(time(NULL));
//string length distribution
for(y=1;y<8;y++) {
for(i=0;i<pow(x,y);i++) {
j = randNbr(2,4);
if(j==2) cnt2++;
if(j==3) cnt3++;
if(j==4) cnt4++;
}
//printf("pow(10,%d) = %.0f\n",y,pow(x,y));
printf("n = %d\n",i);
printf("Count of 2 = %d\n",cnt2);
printf("Count of 3 = %d\n",cnt3);
printf("Count of 4 = %d\n\n",cnt4);
//printf("Total = %d\n\n",cnt2+cnt3+cnt4);
cnt2=0;cnt3=0;cnt4=0;
}
//letter distribution
char charset[62] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
int charsetLen = strlen(charset);
cnt=0;
for(i=0;i<charsetLen;i++) {
for(j=0;j<1000;j++) {
char *randStr = malloc(sizeof(char) * 2);
randStr[0] = charset[randNbr(0,charsetLen-1)];
randStr[1] = '\0';
//if(strcmp(randStr,charset[i])==0) cnt++;
}
printf("Count of %s = %d\n",charset[i],cnt);
cnt = 0;
}
exit(0);
}
---------------------------------------------------------------------------
Maybe you can show me how to fix the //letter distribution part of the
code. I can't get it to compile.
>> Does the number of tries matter? Or is each try an independent event,
>> and so doesn't affect the probability?
>
> You are mixing apples and oranges. Yes, each try is independent. But
> yes, the number of tries matter.
>
> Consider a coin toss. Heads or tails are equally likely. After n
> tosses, the probability of getting a heads on toss n+1 is still 1/2.
> But you question is basically what are the odds of getting at least
> one heads. You would probably stop tossing when the first heads shows
> up. This rewords the question to what is the probability of getting a
> heads on toss n+1 with no heads on the first n tosses. When you limit
> yourself to n tosses, the question becomes what is the probability of
> not getting a heads on n tosses. Then you can say the probability of
> getting at least one heads is 1 - that value.
>
> Getting back to your question, The probability of seeing RUN at least
> once in n strings is 1 - the probability of never seeing RUN. The
> probability of not seeing RUN at all is the product of not seeing RUN
> in string 1 times the probability of not seeing it in string 2 times
> ... times the probability of not seeing it in string n. That product
> is due to the fact that strings are independent but it is obvious that
> the numerical result depends on n.
Thanks Barry
Back to sci.math | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What are the odds? DFS <nospam@dfs.com> - 2019-11-05 22:57 -0500
Re: What are the odds? James Waldby <not@valid.invalid> - 2019-11-06 05:40 +0000
Re: What are the odds? DFS <nospam@dfs.com> - 2019-11-06 10:56 -0500
Re: What are the odds? Barry Schwarz <schwarzb@delq.com> - 2019-11-06 09:16 -0800
Re: What are the odds? Mike Terry <news.dead.person.stones@darjeeling.plus.com> - 2019-11-06 17:28 +0000
Re: What are the odds? Barry Schwarz <schwarzb@delq.com> - 2019-11-06 04:13 -0800
Re: What are the odds? DFS <nospam@dfs.com> - 2019-11-06 10:40 -0500
Re: What are the odds? Barry Schwarz <schwarzb@delq.com> - 2019-11-06 10:08 -0800
Re: What are the odds? Julio Di Egidio <julio@diegidio.name> - 2019-11-06 11:55 -0800
Re: What are the odds? Mike Terry <news.dead.person.stones@darjeeling.plus.com> - 2019-11-06 20:27 +0000
Re: What are the odds? Julio Di Egidio <julio@diegidio.name> - 2019-11-06 12:44 -0800
Re: What are the odds? Julio Di Egidio <julio@diegidio.name> - 2019-11-06 12:55 -0800
Re: What are the odds? Mike Terry <news.dead.person.stones@darjeeling.plus.com> - 2019-11-06 22:05 +0000
Re: What are the odds? Julio Di Egidio <julio@diegidio.name> - 2019-11-06 14:38 -0800
Re: What are the odds? DFS <nospam@dfs.com> - 2019-11-06 15:52 -0500
Re: What are the odds? James Waldby <not@valid.invalid> - 2019-11-07 22:27 +0000
Re: What are the odds? DFS <nospam@dfs.com> - 2019-11-07 18:33 -0500
Re: What are the odds? Mitch Raemsch <mitchrae3323@gmail.com> - 2019-11-06 18:39 -0800
csiph-web