[GENERAL] surprising results with random()

2009-02-23 Thread Jessi Berkelhammer
Hi, I have a view in which I want to randomly assign values if certain conditions hold. I was getting surprising results. Here is a (very) simplified version of the view, which seems to indicate the problem: CREATE OR REPLACE VIEW test_view AS SELECT CASE WHEN random()

Re: [GENERAL] surprising results with random()

2009-02-23 Thread Steve Atkins
On Feb 23, 2009, at 2:09 PM, Jessi Berkelhammer wrote: Hi, I have a view in which I want to randomly assign values if certain conditions hold. I was getting surprising results. Here is a (very) simplified version of the view, which seems to indicate the problem: CREATE OR REPLACE VIEW

Re: [GENERAL] surprising results with random()

2009-02-23 Thread ries van Twisk
Jessi, should the function not look like this??? CREATE OR REPLACE VIEW test_view AS SELECT CASE WHEN random() .3 THEN '1' WHEN random() .5 THEN '2' ELSE '3' END AS test_value FROM client; On Feb 23, 2009, at 5:09 PM,

[Fwd: Re: [GENERAL] surprising results with random()]

2009-02-23 Thread John R Pierce
ries van Twisk wrote: Jessi, should the function not look like this??? CREATE OR REPLACE VIEW test_view AS SELECT CASE WHEN random() .3 THEN '1' WHEN random() .5 THEN '2' ELSE '3' END AS test_value FROM client; actually, I'd think that should be

Re: [GENERAL] surprising results with random()

2009-02-23 Thread Brent Wood
Or perhaps: CREATE OR REPLACE VIEW test_view AS SELECT (random()*3)::int as test_value; At least in this case, that should give the same result. in this case 1/3 should be 1, 1/3 = 2 1/3=3 in your case 1/3 = 1, 1/2 the remainder (1/2 * 2/3 = 1/3) = 2, remaining 1/3 = 3 Although I'm guessing

Re: [Fwd: Re: [GENERAL] surprising results with random()]

2009-02-23 Thread Tom Lane
John R Pierce pie...@hogranch.com writes: ries van Twisk wrote: should the function not look like this??? CREATE OR REPLACE VIEW test_view AS SELECT CASE WHEN random() .3 THEN '1' WHEN random() .5 THEN '2' ELSE '3' END AS test_value FROM client; actually, I'd think that

Re: [GENERAL] surprising results with random()

2009-02-23 Thread raf
Steve Atkins wrote: On Feb 23, 2009, at 2:09 PM, Jessi Berkelhammer wrote: Hi, I have a view in which I want to randomly assign values if certain conditions hold. I was getting surprising results. Here is a (very) simplified version of the view, which seems to indicate the problem:

Re: [GENERAL] surprising results with random()

2009-02-23 Thread Scott Marlowe
On Mon, Feb 23, 2009 at 5:16 PM, raf r...@raf.org wrote: this looks like an attempt to understand the monty hall problem. http://en.wikipedia.org/wiki/Monty_Hall_problem except that there's no goat :( And what database management system can be complete without a goat? :) -- Sent via