Hey everyone, I am having some difficult trying to calculate the probability of a sequence of consecutive ones being generated in an array when the position is chosen randomly.

For example: I want to create an array of length K and which entry will be initialized with 0. Then I will select M number of locations that will be picked randomly, once I chose those position I will set it to 1. Now if I try to this problem N number of times, what is the chance I will get a sequence of 1's?

Like this 1's in an array of 10: 0001111110

this is what I did to pick a random number for the position:

and then I did a loop to set all the positions to 0. After that I called the discrete_uniform function and set the 1's in the array. But I am having trouble trying to do the code to see if I repeat the experiment N number of times what is the chance that all the 1's will be next to each other.Code:long discrete_uniform (long a, long b) { if (b > a) { double x = uniform (); long c = ( a + (long) floor((b-a+1)*x) ); return c; } else if (a == b) return a; else { printf("ERROR in uniform.discrete_uniform(): a=%2ld b=%2ld\n",a,b);return 0;} }

I am a beginner, can anyone help me?