Re: [algogeeks] Re: Random Number generation

2012-10-27 Thread Saurabh Kumar
@Don- Yes, I agree the choice of Random number generator algorithm should very much depend on the underlying application. Thanks, for bringing up the Diehard tests, those are some interesting statistical tests. +1 On 26 October 2012 21:23, Don dondod...@gmail.com wrote: How you chose from the

[algogeeks] Re: Random Number generation

2012-10-26 Thread Don
How you chose from the wide array of pseudo-random generators available depends a lot on how you intend to use it. If you just need something that seems random in a video game, a LCG is probably fine. However, you could fill a large bookshelf with studies which were invalidated because they used

[algogeeks] Re: Random Number generation

2012-10-25 Thread Don
Mersenne Twister is more than sufficient for simulation or most other applications other than encryption. Don On Oct 25, 6:37 am, Anuj Khandelwal anuj.cool.khandel...@gmail.com wrote: hey all, Any idea to generate random number without using rand() function call ? Any algorithms for random

Re: [algogeeks] Re: Random Number Generator

2011-07-07 Thread DeVaNsH gUpTa
I gave this method as you are also expecting random(0,1) to give values either 0 or 1 only, not between these two. Thanks and Regards Devansh Gupta MNNIT, Allahabad -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group,

Re: [algogeeks] Re: Random Number Generator

2011-07-07 Thread Nitish Garg
Yes, Random(0, 1) gives values 0 or 1 only with equal probabilities. But your solution won't work. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit

Re: [algogeeks] Re: Random Number Generator

2011-07-07 Thread surender sanke
if b-a is exactly 2^k-1 , k0 then a + k bits (each bit is set using rand(0 1) ) with equal probability surender On Thu, Jul 7, 2011 at 1:20 PM, Nitish Garg nitishgarg1...@gmail.comwrote: Yes, Random(0, 1) gives values 0 or 1 only with equal probabilities. But your solution won't work. -- You

[algogeeks] Re: Random Number Generator

2011-07-07 Thread Nitish Garg
Thanks Dave, nice solution. By setting the bits we can get equal probabilities. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/Y02NVHYBhdkJ. To post to

[algogeeks] Re: Random Number Generator

2011-07-06 Thread Dave
@Nitish: I'm assuming that Random(0,1) returns 0 and 1 randomly, with equal probability. Let n = ceiling(log_2(b-a+1)). Use the rejection method (http://en.wikipedia.org/wiki/ Rejection_sampling) as follows: Generate an integer, k, 0 = k 2^n, one bit at a time, using Random(0,1) n times. k will

[algogeeks] Re: Random Number Generator

2011-07-06 Thread anonymous procrastination
@surender Yep, I think the same. for(i=0;i(b-a);i++,a+=rand(0,1)); Watsay? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Re: Random Number Generator

2011-07-06 Thread Nitish Garg
Does not look good to me, Here's why : 3+rand(0,1)+rand(0,1)+rand(0,1) : When we have rand(0, 1) + rand(0, 1) + rand(0, 1), a number of possibilities apply: We will have the following cases : 0, 0, 0 or 0, 0, 1 or 0, 1, 0 or 0, 1, 1 or 1, 0, 0 or 1, 0, 1 or 1, 1, 0 or 1, 1, 1, their respective

Re: [algogeeks] Re: random number generator

2011-03-22 Thread kunal srivastav
call function and save each of the results in x and y(say) if x = 0 and y = 1 ...prob = (.6)*(.4) return 0 if x = 1 and y = 0 ...prob = (.4)*(.6) return 1 otherwise, repeat.. hence this new function will return 0 and 1 with 50% prob. On Tue, Mar 22, 2011 at 11:07 PM, Don dondod...@gmail.com

[algogeeks] Re: random number generator

2011-03-22 Thread Don
There is no upper bound on the runtime of this function. On Mar 20, 4:33 pm, Jammy xujiayiy...@gmail.com wrote: clearly the prob. of getting true|false and false|true are equal to 0.6*0.4. Therefore the following code works, bool uniform(){    bool f1;    bool f2;    do{        f1 =

Re: [algogeeks] Re: random number generator

2011-03-22 Thread Xin Xu
bool ff() { while(true) { int a = f() ? 2 : 0; int b = f() ? 0 : -1; if (a + b == 1) return true; if (a + b == 0) return false; } } On Wed, Mar 23, 2011 at 1:54 AM, Don dondod...@gmail.com wrote: There is no upper bound on the runtime of this function.

[algogeeks] Re: random number generator

2011-03-20 Thread cegprakash
i dont know how to write a function which returns true 60% time and false 40% time -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Re: random number generator

2011-03-20 Thread Jammy
clearly the prob. of getting true|false and false|true are equal to 0.6*0.4. Therefore the following code works, bool uniform(){ bool f1; bool f2; do{ f1 = non_uniform(); f2 = non_uniform(); }while(!(f1 ^ f2)); return f1; } On Mar 17, 10:24 am, saurabh agrawal

[algogeeks] Re: random number generator

2011-03-19 Thread cegprakash
@gene: can u give the function for unfair_coin_toss so that i can understand what u are doing in fair_coin_toss On Mar 19, 9:54 am, Gene gene.ress...@gmail.com wrote: On Friday, March 18, 2011 1:47:45 PM UTC-4, Gene wrote: On Mar 17, 10:24 am, saurabh agrawal saura...@gmail.com wrote:

[algogeeks] Re: random number generator

2011-03-19 Thread Gene
On Saturday, March 19, 2011 6:07:44 AM UTC-4, cegprakash wrote: @gene: can u give the function for unfair_coin_toss so that i can understand what u are doing in fair_coin_toss On Mar 19, 9:54 am, Gene gene.r...@gmail.com wrote: On Friday, March 18, 2011 1:47:45 PM UTC-4, Gene wrote:

[algogeeks] Re: random number generator

2011-03-18 Thread Gene
On Mar 17, 10:24 am, saurabh agrawal saurabh...@gmail.com wrote: Given a  function which returns true 60% time and false 40% time. Using this function you have to write a function which returns true 50% of the time. If we call the function N times, then the probability that we'll have K true

[algogeeks] Re: random number generator

2011-03-18 Thread Gene
On Friday, March 18, 2011 1:47:45 PM UTC-4, Gene wrote: On Mar 17, 10:24 am, saurabh agrawal saura...@gmail.com wrote: Given a function which returns true 60% time and false 40% time. Using this function you have to write a function which returns true 50% of the time. If we

[algogeeks] Re: random number generator

2011-03-17 Thread Don
bool uniform() { static bool state = true; state = !state; return state ^ nonuniform(); } On Mar 17, 9:24 am, saurabh agrawal saurabh...@gmail.com wrote: Given a  function which returns true 60% time and false 40% time. Using this function you have to write a function which returns true

[algogeeks] Re: random number generator

2011-03-17 Thread Dave
@Don: Clever and efficient code to meet the problem statement precisely. It does give true on half of the calls, but it doesn't give true with probability 50% on any given call, so we wouldn't want to use it to model a fair coin. Dave On Mar 17, 1:03 pm, Don dondod...@gmail.com wrote: bool

[algogeeks] Re: random number [a....b]

2009-10-06 Thread Neeraj Singh
@harit random number means its output cant be predicted,it doesnt mean that the probability will be equal for any number of test runs. e.g consider random number between 3-5 for 3 test runs if the first output is 4 second is 3 then to ensure same probability third output must be 5 which makes

[algogeeks] Re: random number...

2009-10-02 Thread eSKay
okay thanks On Sep 20, 2:59 am, Gene gene.ress...@gmail.com wrote: On Sep 18, 5:45 pm, eSKay catchyouraak...@gmail.com wrote: okay now I get it. but then int i; do {   i = 5 * (rand5() - 1) + rand5();  // i is now

[algogeeks] Re: random number...

2009-09-28 Thread manish bhatia
How are you picking ni from [a...b] range (length 7) ? From: avalon avalo...@gmail.com To: Algorithm Geeks algogeeks@googlegroups.com Sent: Saturday, 19 September, 2009 2:16:47 PM Subject: [algogeeks] Re: random number... Forgive me first if i am wrong since

[algogeeks] Re: random number...

2009-09-20 Thread Walter
Isn't it the same of adding two random numbers When you just add two random numbers, you tend to normalize them. If you simply multiply one of them by 5 before adding with the other, you'll end up normalizing them the same way... On 18 set, 18:45, eSKay catchyouraak...@gmail.com wrote:

[algogeeks] Re: random number...

2009-09-20 Thread Dave
Walter, when you roll two dice, you get two random numbers between 1 and 6 inclusive. Each has an essentially uniform distribution, but the sum does not. Of every 36 rolls, you will average one 2, two 3s, three 4s, four 5s, five 6s, six 7s, five 8s, four 9s, three 10s, two 11s, and one 12. The

[algogeeks] Re: random number...

2009-09-19 Thread eSKay
okay now I get it. but then int i; do { i = 5 * (rand5() - 1) + rand5(); // i is now uniformly random between 1 and 25 } while(i 7); return i; should be fine. isn't it??

[algogeeks] Re: random number...

2009-09-19 Thread Neeraj Singh
Random number between any two numbers (a,b) can also be obtained as follows. let rand() return a random number between 0 and 1 ; int random(a,b) { if(a==b) return a ; mid = a + (b-a)/2 ; if( rand() ) return random(mid,b) ; else return random(a,mid) ; } I think probability of each

[algogeeks] Re: random number...

2009-09-19 Thread Gene
On Sep 18, 5:45 pm, eSKay catchyouraak...@gmail.com wrote: okay now I get it. but then int i; do {   i = 5 * (rand5() - 1) + rand5();  // i is now uniformly random between 1 and 25 } while(i 7); return i;

[algogeeks] Re: random number...

2009-09-19 Thread Gene
On Sep 19, 4:46 am, avalon avalo...@gmail.com wrote: Forgive me first if i am wrong since i didn't read all the posting ... Here is a way to sol the problem. n1 = random_1_5() + 0; n2 = random_1_5() + 5; .. n7= random_1_5() + (7-1)*5; now n1 ... n7  is in range [1 ... 35] Image we divde

[algogeeks] Re: random number...

2009-09-18 Thread eSKay
one of the solutions given at http://stackoverflow.com/questions/137783/given-a-function-which-produces-a-random-integer-in-the-range-1-to-5-write-a-fun is: int i; do { i = 5 * (rand5() - 1) + rand5(); // i is now uniformly random

[algogeeks] Re: random number...

2009-09-18 Thread Dave
What is wrong with using i = rand5() + rand5() instead of i = 5 * rand5 () + rand5() is that the former is not uniformly distributed between 1 and 10, as claimed. First, 1 never occurs. 2 occurs 1 out of 25 times, 3 occurs 2 out of 25, etc. (Think of rolling two ordinary dice.) Dave On Sep 18,

[algogeeks] Re: random number...

2009-09-18 Thread Gene
On Sep 7, 11:56 am, ankur aggarwal ankur.mast@gmail.com wrote:   Given a random number generator that generates numbers in the range 1 to 5, how can u create a random number generator to generate numbers in the range 1 to 7. (remember that the generated random numbers should follow a

[algogeeks] Re: random number...

2009-09-09 Thread manish bhatia
dave_and_da...@juno.com To: Algorithm Geeks algogeeks@googlegroups.com Sent: Wednesday, 9 September, 2009 2:42:26 AM Subject: [algogeeks] Re: random number... Manish, your first approach doesn't work. You will notice that b1, b2, and b3 each are 0 2/5 of the time and 1 3/5 of the time, so the return value

[algogeeks] Re: random number...

2009-09-08 Thread ankur aggarwal
@dave * *On Tue, Sep 8, 2009 at 7:27 AM, Dave dave_and_da...@juno.com wrote: Use the rejection technique, something like this: do { do U1 = random_1_to_5(); while( U1 == 5 ); // At this point, U1 is a uniform integer in the range 1 to 4. U2 = random_1_to_5(); * if(

[algogeeks] Re: random number...

2009-09-08 Thread Dufus
Hardest part of this problem is to prove that the generated number INDEED follow uniform distribution :D _dufus On Sep 8, 6:57 am, Dave dave_and_da...@juno.com wrote: Use the rejection technique, something like this: do {     do         U1 = random_1_to_5();     while( U1 == 5 ); // At

[algogeeks] Re: random number...

2009-09-08 Thread ankur aggarwal
@dufus tell me 1 thing do we have to make algo so that the prob is 1/7 or do we have to make so that prob of generating number between 1 to 7 is same may be( 1/10) etc ??? On Tue, Sep 8, 2009 at 11:42 AM, Dufus rahul.dev.si...@gmail.com wrote: Hardest part of this problem is to prove that the

[algogeeks] Re: random number...

2009-09-08 Thread Dave
Your comment is moot, since if any random number generator returns the same number forever, you are not going to be able to use it to generate other random numbers with a uniform density. On Sep 8, 9:04 am, Karthik Singaram Lakshmanan karthiksinga...@gmail.com wrote:      The rejection

[algogeeks] Re: random number...

2009-09-08 Thread ankur aggarwal
@karthik but look at the prob part.. it seems ok 2 me.. it is random generator u cannot guarntee which number is going 2 come.. On Tue, Sep 8, 2009 at 7:34 PM, Karthik Singaram Lakshmanan karthiksinga...@gmail.com wrote: The rejection technique may never halt...(with an infinitesimally

[algogeeks] Re: random number...

2009-09-08 Thread ankur aggarwal
@dave plz quote the name of the person u r taking / pointing.. On Tue, Sep 8, 2009 at 8:11 PM, Dave dave_and_da...@juno.com wrote: Your comment is moot, since if any random number generator returns the same number forever, you are not going to be able to use it to generate other random

[algogeeks] Re: random number...

2009-09-08 Thread ankur aggarwal
On Tue, Sep 8, 2009 at 9:04 PM, ankur aggarwal ankur.mast@gmail.comwrote: @dave plz quote the name of the person u r *talking* / pointing.. On Tue, Sep 8, 2009 at 8:11 PM, Dave dave_and_da...@juno.com wrote: Your comment is moot, since if any random number generator returns the same

[algogeeks] Re: random number...

2009-09-08 Thread Dave
Huh? You'll note his posting is appended to mine, just as your posting, my posting, and part of his posting are appended to this one. On Sep 8, 10:34 am, ankur aggarwal ankur.mast@gmail.com wrote: @dave plz quote the name of the person u r taking / pointing.. On Tue, Sep 8, 2009 at

[algogeeks] Re: random number...

2009-09-08 Thread Dave
Ramaswamy, summing seven uniform random numbers doesn't give a uniform result. Even the sum of two random numbers is not uniform. Consider rolling two dice. 2 occurs only 1 out of 36 times, while 7 occurs 6 out of 36 times. Dave On Sep 8, 2:34 pm, Ramaswamy R ramaswam...@gmail.com wrote:

[algogeeks] Re: random number...

2009-09-08 Thread Dave
Manish, your first approach doesn't work. You will notice that b1, b2, and b3 each are 0 2/5 of the time and 1 3/5 of the time, so the return value is not uniformly distributed. For approach 2, what do you have to do if you want an exactly uniform distribution as a result? Or what would the code

[algogeeks] Re: random number...

2009-09-08 Thread Ramaswamy R
Generate the random number 7 times. Sum them all and divide by 5. Theoritically it should be evenly distributed over 1-7. But owing to random number generators characteristics the sum of rand(5) called 7 times may not be perfectly evenly distributed over 1-7. A nice discussion on some neat options

[algogeeks] Re: random number...

2009-09-08 Thread Karthik Singaram Lakshmanan
Not that I am trying to prove a point...but just trying to clarify what I said... A uniform random number generator, say rand_5() produces a value 2 with probability 1/5 it can produce a sequence of two 2s with probability (1/5)^2 it can produce a sequence of three 2s with probability (1/5)^3

[algogeeks] Re: random number...

2009-09-07 Thread ankur aggarwal
I KNow a sol for given a rand_5() function which generates *0* to 5 and we have to find rand_7() for *0* to 7 could not think about it... On Mon, Sep 7, 2009 at 9:26 PM, ankur aggarwal ankur.mast@gmail.comwrote: Given a random number generator that generates numbers in the range 1 to

[algogeeks] Re: random number...

2009-09-07 Thread Nagendra Kumar
@ankur: u r right. On Mon, Sep 7, 2009 at 9:36 PM, ankur aggarwalankur.mast@gmail.com wrote: I KNow a sol for given a rand_5() function which generates 0 to 5 and we have to find rand_7() for 0 to 7 could not think about it... On Mon, Sep 7, 2009 at 9:26 PM, ankur aggarwal

[algogeeks] Re: random number...

2009-09-07 Thread Dave
Use the rejection technique, something like this: do { do U1 = random_1_to_5(); while( U1 == 5 ); // At this point, U1 is a uniform integer in the range 1 to 4. U2 = random_1_to_5(); if( U1 2 ) U2 += 5; } while( U2 7 ); // At this point, U2 is a uniform random

[algogeeks] Re: random number generator

2007-05-17 Thread [EMAIL PROTECTED]
Monu Rathour wrote: i worked in *visual studio 8*,and there is a function *rand()* to generate random numbers. But now i have to work on *visual studio 6*, is there any such function? rand() is the function provided by the standard C library (stdlib), so as long as you're using an ANSI C