[algogeeks] Re: (need help) How to solve this random number generatioin problem?

2007-01-31 Thread [EMAIL PROTECTED]
ok, this is a lame attempt - can someone explain if it's correct, or why not : int limited_rand() { return rand() % 8 + 1; } value = limited_rand() % 3 + limited_rand(); On Jan 31, 7:29 am, Ming \(Amos\) Zhang [EMAIL PROTECTED] wrote: It's not uniformly distributed, suppose the given

[algogeeks] Re: fibonacci numbers

2007-01-31 Thread stone
I think the method given by Paul is practical. the precise expression of F(n) is F(n) = K * (x1^n - x2^n ) where K = 1/sqrt(5), x1 = (1+sqrt(5))/2 and x2 = (1-sqrt(5))/2 because the x2 is small (about -0.61803...), the bigger n is ,the smaller the x2^n is. so, we consider K*(x1^2) is similar to

[algogeeks] How to list all combination of C(n,k)

2007-01-31 Thread sofin
Hi there, How to write a c program to list all combinations of C(n,k), where 1 = k =n and n is a variable. For example, n=3, C(3,k). k=1, {1},{2},{3} k=2, {1,2}, {1,3}, {2,3} k=3, {1,2,3} --~--~-~--~~~---~--~~ You received this message because you are subscribed

[algogeeks] Re: How to list all combination of C(n,k)

2007-01-31 Thread Sandesh
recur( start , filled){ if start k then print else { for i=start to n } } On Jan 31, 9:34 pm, sofin [EMAIL PROTECTED] wrote: Hi there, How to write a c program to list all combinations of C(n,k), where 1 = k =n and n is a variable. For example, n=3, C(3,k). k=1, {1},{2},{3}

[algogeeks] Re: (need help) How to solve this random number generatioin problem?

2007-01-31 Thread Pradeep Muthukrishnan
Here's my lame attempt. Output is uniformly distributed if input is so. 1 - 20.065% 2 - 19.986% 3 - 19.989% 4 - 19.964% 5 - 19.996% 1 - 14.352% 2 - 14.302% 3 - 14.281% 4 - 14.285% 5 - 14.295% 6 - 14.252% 7 - 14.233% /* */ #includestdio.h #includestdlib.h #includestring.h int

[algogeeks] Re: How to list all combination of C(n,k)

2007-01-31 Thread Sandesh
recur( start , fill){ if start k then print else { for i=start to n { a[fill] = i recur ( start+1, fill+1) } } } array a, n k are global variables. and call the function as recur(1,1) On Jan 31, 9:57 pm, Sandesh [EMAIL PROTECTED] wrote: recur( start , filled){

[algogeeks] Re: (need help) How to solve this random number generatioin problem?

2007-01-31 Thread Gene
On Jan 30, 8:57 pm, Jialin [EMAIL PROTECTED] wrote: Question: Given a program which can generate one of {1, 2, 3, 4, 5} randomly. How can we get another generator which can generate one of {1,2,3,4,5,6,7} randomly? Thank you! If you generate random 1 to 5 twice, there are 25 equally

[algogeeks] Re: (need help) How to solve this random number generatioin problem?

2007-01-31 Thread pramod
Why can't we simply take the 1..5 random number, multiply by 7 and divide by 5. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Re: (need help) How to solve this random number generatioin problem?

2007-01-31 Thread Prunthaban Kanthakumar
Then you will get only the following numbers (1*7)/5 = 1 (2*7)/5 = 2 (3*7)/5 = 4 (4*7)/5 = 5 (5*7)/5 = 7 What you will do to get 3 and 6? On 2/1/07, pramod [EMAIL PROTECTED] wrote: Why can't we simply take the 1..5 random number, multiply by 7 and divide by 5.