Choose a random number between 0 and 1. Add it to 0. Choose another random number between 0 and 1 and add it to your previous sum. If your sum exceeds 1, stop, otherwise continue the same process. Store the number of choices you had to make. It seems that the average(total choices divided by total iterations) converges to $e$. Here is an equivalent Python code: import random Total_choices=0 Tries=1 choices=0 Total=0 iterations=1000 while Tries&lt;=iterations:     while Total&lt;1:         Total=Total+random.uniform(0,1)         choices=choices+1     Total=0     Total_choices=Total_choices+choices     choices=0     Tries=Tries+1 print(Total_choices) print(Total_choices/iterations)       Following are some examples of outputs that I got from which I hypothesized the above statement:  Iterations=100 average=2.62 Iterations=1000 average=2.752 Iterations=10000 average=2.7131  Is my hypothesis correct? If yes then why does this happen? P.S if you can suggest a more appropriate title and I thought perhaps this question is more appropriate for this community instead of
80966
I define $X_i$ as a random variable that is uniformly distributed between (0,1). What is the expected number of such variables I require to make the sum go just higher than 1.  Thanks
12929
Could someone please tell me what I'm doing wrong with this code? It is just printing 'count' anyway.  I just want a very simple prime generator (nothing fancy).   import math  def main():     count = 3     one = 1     while one == 1:         for x in range(2, int(math.sqrt(count) + 1)):             if count % x == 0:                  continue             if count % x != 0:                 print count          count += 1
69633
Let's say you tell me to produce randomly a number from 1-100, and I choose the number 47. Can it be said that there is a specific reason I chose the number 47, and that it is not completely random? By random I mean that there is absolutely no reason this number in particular was chosen.    It seems odd to me, since it seems like since I have applied conscious effort to produce or choose a number within that range, or even without range, that it can't be truly random, but there might be a reason why I chose that number amongst the many others I could have chosen.  I guess the general question, which I'm interested to know if any philosophers in the past have discussed, is whether our thoughts are necessarily based on prior thoughts, or if thoughts can be truly spontaneous and random?
6371
I have seen that the method of "dominated convergence" implies that sometimes a limit cannot be brought inside of a sum, but is there a more basic way to understand this, preferably without using integrals?   A conceptual or simple answer would be helpful. Thank you!
68990
Sample $k$ times with order from $n$ distinct numbers with replacement where $k\ge n$. Here "with order" means the sample is treated like a sequence rather than a set, so results like "1,3,3" and "3,1,3" are different.  The question is what is the probability that every number is sampled at least once? My answer is $1-\frac{{\sum\limits_{i = 1}^n {C_n^i\times i! \times {{(n - i)}^k}} }}{{{n^k}}}$ where $C_n^i$ denotes $n$ chooses $i$.  ${C_n^i\times i! \times {{(n - i)}^k}}$ means first choose $i$ ($i=1,2,...,n-1$) of numbers not to appear in the sample, and then we sample from the remaining $n-i$ numbers for $k$ times.   My question is, is there more elegant solution where the numerator can be directly computed? i.e. can we directly calculate the number of possible sample sequences in which every number has at least one occurrence? Thank you!    PS: my attempt was $C_k^n\times n!\times n^{n-k}$, meaning that we first choose $n$ positions in the sequence of length $k$ to place $n$ numbers, and then permute the $n$ numbers. This is to ensure every number to appear once. The remaining $n-k$ are sampled from the $n$ numbers without restriction.   However, I later found this seems not correct, and it counts the same sequence multiple times.  PS2: as pointed out in the comments, my first answer "1- ..." is not correct either.
99940
Let $(E_n)$ be a sequence of events in a probability space such that $$\lim_{n\to\infty}\mathbb P(E_n)=0.$$ I am trying to prove that if $$\sum_{n=1}^\infty\mathbb P (E_n\setminus E_{n+1}) &lt;\infty$$ then $$\mathbb P\left(\limsup_{n\to\infty} E_n\right)=0.$$  For an example I am using the sequence of intervals $[0, 1/n]$ which goes to $0$ as $n$ increases to infinity. Then I can see how the probability of infinite sum of the intersection of the $E_n$ and the complement of $E_{n+1}$  is less than infinity and the probability of $\limsup_{n\to\infty} E_n$ equals zero.   Can anyone help me figure out how to prove this in general using any sequence? Especially to show how $\mathbb P\left(\limsup_{n\to\infty} E_n\right)=0$?  Thank you in advance for your thoughts.
23692
Consider a game where one would roll a random integer between $1$ and $N_0$ where $N_0 \ge 1$. The newly randomly generated number is now the new &quot;upper limit&quot; of the game, the game continues by rolling a random number between $1$ and the randomly generated number. This game continues until the randomly generated number is 1. Here is an example of how it can look like. Consider $N_0 = 1000$ $$N_1 = Random(1, N_0) = Random(1, 1000) = 623$$ $$N_2 = Random(1, N_1) = Random(1, 623) = 366$$ $$N_3 = Random(1, N_2) = Random(1, 366) = 303$$ $$N_4 = Random(1, N_3) = Random(1, 303) = 190$$ $$N_5 = Random(1, N_4) = Random(1, 190) = 52$$ $$N_6 = Random(1, N_5) = Random(1, 52) = 13$$ $$N_7 = Random(1, N_6) = Random(1, 13) = 1$$ $$END$$ The Length of the example game was 7, it took 7 rolls to reach 1. Given the Starting Upper Limit $N_0$, what is the average amount of rolls needed to reach 1? I have tried to write Python code to help with this problem and it seems this follows a Logarithmic Pattern with the function to approximate the amount is $f(N_0) = 1.0168287465013466\ln(N_0) + 1.4731706151125865$
20736
I want to show that a sequence $(a_n:n \in \mathbb N)$ converges to a limit $L \in \mathbb R$ if, and only if, an N-th tail of the sequences converges to $L$ for some $N \in \mathbb N$. For each $N \in \mathbb N$, an N-th tail sequence can be defined as $(t_n:n \in \mathbb N)$ where $t_n := a_{N+n}$.  Using the definition of a limit for the sequence $(a_n:n \in \mathbb N)$, we have the following:  For every $0 \lt \epsilon$, there is a natural number $N_{\epsilon} \in \mathbb N$ such that for all $N_{\epsilon} \lt n$, $|a_n - L| \lt \epsilon$. But I'm not sure what to do next in order to show that the $N$-th tail converges. Which natural number should I choose for the $N$-tail? Any help would be much appreciated.
36924
Is there a reasonable statistic test one can do to standard random number generators (say, one of those that come built in in Python libs) which shows they are not really random?  (By reasonable I mean to exclude silly things like «generate a looong list and see that it is periodic»)  Later: Notice I am looking for a test that fails on standard generators.
23075
How do I generate numbers based on an arbitrary discrete distribution?  For example, I have a set of numbers that I want to generate. Say they are labelled from 1-3 as follows.  1: 4%, 2: 50%, 3: 46%  Basically, the percentages are probabilities that they will appear in the output from the random number generator. I have a pesudorandom number generator that will generate a uniform distribution in the interval [0, 1]. Is there any way of doing this?   There are no bounds on how many elements I can have, but the % will add up to 100%.
31694
Given a function which produces a random integer in the range 1 to 5, write a function which produces a random integer in the range 1 to 7.   What is a simple solution? What is an effective solution to reduce memory usage or run on a slower CPU?
68945
I was implementing a simple scheme of Bernoulli distribution sampler. $ X \sim B(p) $. I have a function that generates a uniform random number $r \in (0,1)$. Then, I set $ X = 1 $  if $p &gt; r $, and $X =0$ otherwise. Is this correct?
77115
Let $a_n=1-2^{\frac{-1}{n}}$, $b_n=\frac{1}{n^p}$. Does $\sum_{n=1}^{\infty}a_n$ converge or diverge when compared to $\sum_{n=1}^{\infty}b_n$ if $p &lt; 1$? My answer to this is that it diverges, since $b_n$ diverges if $p&lt;1$, and by a comparison test $a_n$ does as well. Is this correct? Thank you.
40871
Probability that $X \ge Y$ given N rolls on a $d20$  Example:  Originally, we wanted to roll a $13$ or higher $7$ times in a row. In and attempt to improve the odds and make it easier to understand we changed it to be $7(N)$ $d20s$ where one must be greater than or equal to $91(Y)$. So, what is the probability that $X$(sum of rolls) is greater than or equal to $Y(91)$ given $N(7 rolls)?$   We think the answer is $0.16%$ or $1/625$ because in order to achieve the minimum of $91$, one must roll at least a $13$ on every roll. What we're wondering is does the fact that it's now cumulative change the probability?  Thanks for your time.
91987
I am taking a course on Monte Carlo methods and we learned the Rejection Sampling (or Accept-Reject Sampling) method in the last lecture. There are a lot of resources on the web which shows the proof of this method but somehow I am not convinced with them.  So, in the Rejection Sampling, we have a distribution $f(x)$ which is hard to sample from. We choose a easy-to-sample distribution $g(x)$ and find a coefficient $c$ such that $f(x) \leq cg(x)$. Then we sample from $g(x)$ and for each draw, $x_i$, we also sample a $u$ from a standard uniform distribution $U(u|0,1)$.  The sample $x_i$ is accepted if it is $cg(x_i)u \leq f(x_i)$ and rejected otherwise.  The proofs which I came across usually just show that $p(x|Accept) = f(x)$ and stop there.   What I think about this process is that we have a sequence of variables $x_1,Accept_1,x_2,Accept_2,...,x_n,Accept_n$ and a $x_i,Accept_i$ pair corresponds to our i.th sample ($x_i$) and whether it is accepted ($Accept_i$). We know that each $x_i,Accept_i$ pair is independent of each other, such that:  $P(x_1,Accept_1,x_2,Accept_2,...,x_n,Accept_n) = \prod\limits_{i=1}^n P(x_i,Accept_i)$  For a $(x_i,Accept_i)$ pair we know that $P(x_i) = g(x_i)$ and $P(Accept_i|x_i) = \frac{f(x_i)}{cg(x_i)}$. We can readily calculate $p(x_i|Accept_i)$ but I don't understand how it suffices as a proof. We need to show that the algorithm works, so I think a proof should show that the empricial distribution of the accepted samples converge to $f(x)$ as $n\rightarrow\infty$. I mean, with $n$ being the number of all accepted and rejected samples:  $\frac{Number \hspace{1mm} of \hspace{1mm} samples \hspace{1mm} with \hspace{1mm} (A \leq x_i \leq B)}{Number \hspace{1mm} of \hspace{1mm} accepted \hspace{1mm} samples} \rightarrow \int_A^B f(x)dx$    as    $n\rightarrow\infty$.  Am I wrong with this thought pattern? Or is there a connection between the common proof of the algorithm and this?   Thanks in advance
40813
This is a really natural question for which I know a stunning solution. So I admit I have a solution, however I would like to see if anybody will come up with something different. The question is     What is the probability that two numbers randomly chosen are coprime?   More formally, calculate the limit as $n\to\infty$ of the probability that two randomly chosen numbers, both less than $n$ are coprime.
43399
I was able to prove, hopefully correctly, that the sum converges uniformly. But, I'm not sure how to show it converges uniformly specifically to $f$.  The way I proved it converges uniformly was by using the Dirichlet convergence test, by taking $a_k(x) = \frac1n$ and $b_k(x) = f_k(x)$. $\sum_{k=1}^n{b_k(x)}$ is uniformly bounded on $[0,1]$ by $n+2$ for instance, and $a_n$ is monotone and uniformly convergent to 0 because it does not depend on the value of $x$.  I got rather stuck after this. I guess I have to use the continuity of the functions and the uniform convergence of both, but I can't figure out how to show that they converge to the same thing. Any help will be greatly appreciated.