I have this code -  number1, number2, number3, number4, number5 = Array.new(5) { rand(99999)+1 }   How can I make sure that each number is unique? Also - is it possible to output all numbers as 5 digit? Like 00147 instead of 147?  Thanks for help!
120783
This is what I have so far:    myArray.map!{ rand(max) }   Obviously, however, sometimes the numbers in the list are not unique. How can I make sure my list only contains unique numbers without having to create a bigger list from which I then just pick the n unique numbers?  Edit: I'd really like to see this done w/o loop - if at all possible.
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?
111126
I tried this problem by counting the number of 5-digit numbers and then dividing it by 2 just like we do for three digits. Please help. Thank you.
108191
I was looking at a 10x10 multiplication table, and I decided to count the unique products. There are 42 out of a possible 100 numbers represented. I had to wonder, why 42? I counted the 58 non-listed numbers -- most of them are either primes >10 or multiples of those primes. I couldn't figure out a satisfying reason like that for 75, 84, 96 and 98. I feel like the number 42 should be calculable from the natural log of 100 and 10, or something, but I can't really figure it out.  Also, I counted the frequency of all the numbers represented. They all have either 1, 2, 3, or 4 instances. The six numbers that have only 1 instance are all squares -- those of 1, 5, 7, 8, 9, and 10. This makes sense -- squares don't fall into that 4x5 = 5x4 redundancy. The 23 numbers with 2 instances are kind of the default I guess. The four with 3 are the remaining squares -- 4, 9, 16, and 36. 4 and 9 make sense to me, as they are squares within the basic range of the times table, so they are hit by themselves, their square root, and 1. I'm having trouble accounting for why 16 and 36 have three representatives. I'm also having trouble seeing the pattern (or patterns) in the numbers with four representatives.  I ultimately want to find a way to, given a times table of any size, calculate whether a given number will appear, and how many times.  Also, I'm pretty sure that for times tables 7x7 and below, more than half of the possible numbers are represented on the table, but for times tables above 7x7, less than half are represented. Why is 7 the turning point?
10279
What would be the best algorithm for finding a number that occurs only once in a list which has all other numbers occurring exactly twice.  So, in the list of integers (lets take it as an array) each integer repeats exactly twice, except one. To find that one, what is the best algorithm.
120455
I have been given $25$ objects numbered from $1$ to $25$ and a set $S = \{-2, -1, 0, 1, 2\}$. I have to choose a random number from the given set and add it to all the objects. I have to do this $5$ times. What will be the expected sum of all objects after all $5$ turns?
81118
How many 6 digit numbers are possible with at most three digits repeated?  My attempt:  The possibilities are:   A)(3,2,1) One set of three repeated digit, another set of two repeated digit and another digit (Like, 353325, 126161)  B)(3,1,1,1) One set of three repeated digit, and three different digits.(Like 446394, 888764)  C)(2,2,1,1) Two sets of two repeated digits and two different digits (Like, 363615, 445598)  D)(2,2,2) Three sets of two repeated digits (Like, 223344, 547547)  E)(2,1,1,1,1,1) One set of two repeated digit and four different digits (Like 317653, 770986)  F)(1,1,1,1,1,1) Six Different digits (like 457326, 912568)  G)(3,3) Two pairs of three repeated digits. Let's try to calculate each possibilities separately.    F) is the easiest calculate.   Let us try to workout  Case E)  Let's divide the case into two parts:  Case E(1) Zero is not one of the digit   We can choose any $5$ numbers form $9$ numbers $(1,2,3,\cdot, 9)$ in $\binom{9}{5}$ ways , the digit which one is repeated can be chosen in 5 ways, and you can permute the digits in $\frac{6!}{2!}$ ways. The total number of ways$=\binom{9}{5}\times 5\times \frac{6!}{2!} $  Case E(2) Zero is one of the digit.  Case E(2)(a) Zero is the repeated digit We need to choose four other numbers which can be done in $\binom{9}{4}$ ways, the digits can be permuted in $\frac{6!}{2!}$ ways, but we need to exclude the once which starts with zero ($5!$ many). The total number of ways =$=\binom{9}{4}\times  (\frac{6!}{2!} -5!)$.  Case E(2)(b) Zero is not the repeated digit We need to choose four other numbers which can be done in $\binom{9}{4}$ ways, the repeated digit can be chosen in 4 ways,  the digits can be permuted in $\frac{6!}{2!}$ ways, but we need to exclude the once which starts with zero ($5!$ many). The total number of ways =$=\binom{9}{4}\times 4\times  (\frac{6!}{2!} -5!)$.  Before, proceeding to workout the other cases, I want to know   Is my attempt correct? If it is correct, it is too lengthy, is there any other way to solve this?
52342
I need to randomly 'sort' a list of integers (0-1999) in the most efficient way possible.  Any ideas?  Currently, I am doing something like this:  bool[] bIndexSet = new bool[iItemCount];  for (int iCurIndex = 0; iCurIndex &lt; iItemCount; iCurIndex++) {     int iSwapIndex = random.Next(iItemCount);     if (!bIndexSet[iSwapIndex] &amp;&amp; iSwapIndex != iCurIndex)     {         int iTemp = values[iSwapIndex];         values[iSwapIndex] = values[iCurIndex];         values[iCurIndex] = values[iSwapIndex];         bIndexSet[iCurIndex] = true;         bIndexSet[iSwapIndex] = true;     } }
41709
My homework asks me the following:     If a student writes the integers from 5 to 305 inclusive by hand, how many times will she write the digit 5?   I started out by writing every number that contains 5 and I got 31, but 31 is not among the answers possible:     5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195, 205, 215, 225, 235, 245, 255, 265, 275, 285, 295, 305   I counted 55, 155, and 255 as two each since there are two occurrences of the digit 5 in each.  I can't figure out what I'm doing wrong.  In addition, suppose I were given the numbers 1 and 100,000 - writing them out isn't efficient, and I would assume there's a formula for this but I can't figure that out either.
71362
I can see that this works for any integer $n$, but I can't figure out why this works, or why the number $42$ has this property.
7814
If "x" is a 9 digit number , which contains digits from 1 to 9 which ends in 5 . Prove that it can't be a perfect square ( digits are not to be repeated).  Please suggest the solution of this question.
25736
I need some advice as I am struggling with the following combinatorics exercise.  Let $k$ be a given positive integer. Show that any non-negative integer $N$ can be written uniquely in the form $$N=\binom{x_k}{k}+\binom{x_{k-1}}{k-1}+\dots+\binom{x_1}{1},$$ where $0 \leq x_1 &lt; \dots &lt; x_{k-1} &lt; x_k$.  The exercise is accompanied by this advice:  Let $x$ be such that $\binom{x}{k} \leq N &lt; \binom{x+1}{k}$. Then any possible representation has $x_k = x$. Now use induction and the fact that $N-\binom{x}{k} &lt; \binom{x}{k-1}$ to show the existence and uniqueness of the representation.  I am really stuck and thus grateful for the slightest hint on how to solve it.
19426
If I have a string "1 2 3 2 1" - or an array [1,2,3,2,1] - how can I select the unique values, i.e.  "1 2 3 2 1" produces "1 2 3"    or  [1,2,3,2,1] produces [1,2,3]   Similar to uniq but uniq seems to work on whole lines, not patterns within a line...
11305
How many integers from 1-999 do not have any repeated digits?  The answer is explained in this , but why is the last set 9*9*8? Why not 9*9*9?
99775
Suppose I have a set of 100 integers. I randomly choose 10 of those, make a note of which ones I selected, and repeat the process. What is the expected number of times this process must be repeated before I see all 100 integers?  I'm also greatly interested in how this is calculated as I'm trying to increase the expected number of times this process is repeated by changing the set sizes.
80428
I have a class like this:  public class myClass {   public List&lt;myOtherClass&gt; anewlist = new List&lt;myOtherClass&gt;;    public void addToList(myOtherClass tmp)   {     anewList.Add(tmp);   }  }   So I call "addToList" a hundred times, each adding a unique item to the list.  I've tested my items to show that before I run the "addToList" method, they are unique.  I even put a line in to test "tmp" to make sure it was what I was expecting.  However, when I do this (lets say myClass object is called tmpClass):  int i = tmpClass.anewList.Count(); for (int j = 0; j&lt;i; j++) {    //write out each member of the list based on index j... }   I get the same exact item, and it's the last one that was written into my list.  It's as if when I add, I'm overwriting the entire list with the last item I've added.    Help?  This makes no sense. I've also tried List.Insert, where I'm always inserting at the end or at index 0.  Still no dice.  Yes, I'm doubly source my indexing is correct and when I do my test I'm indexing through each of the elements.  :)  UPDATE: Okay, I tried this and still had the same problem:  foreach(myOtherClass tmpC in tmpClass.anewList) {         Console.WriteLine(tmpC.theStringInMyClass.ToString()); }   and still for each of the 100 items, I got the same string output... I'm sure I'm doing something completely stupid, but I don't know what yet. I'm still 100% sure that the right string is getting passed in to begin with.  -Adeena    Okay, I tried this and still had the same problem:  foreach(myOtherClass tmpC in tmpClass.anewList) {     Console.WriteLine(tmpC.theStringInMyClass.ToString()); }   and still for each of the 100 items, I got the same string output...  I'm sure I'm doing something completely stupid, but I don't know what yet. I'm still 100% sure that the right string is getting passed in to begin with.  -Adeena
23615
I'm trying to create globally-unique identifiers in JavaScript.  I'm not sure what routines are available on all browsers, how &quot;random&quot; and seeded the built-in random number generator is, etc. The GUID / UUID should be at least 32 characters and should stay in the ASCII range to avoid trouble when passing them around.