0 registered members (),
18,435
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: NVidia Number Test
[Re: broozar]
#162317
10/22/07 20:54
10/22/07 20:54
|
Joined: May 2002
Posts: 7,441
ventilator
Senior Expert
|
Senior Expert
Joined: May 2002
Posts: 7,441
|
with rand() it would be too easy!  19531 is the result if all rand5() return 1. so it's the minimum. i want the minimum to be 0 though so i do the subtraction. hm... i think this solution isn't 100% mathematically correct though even if it seems to give correct results. the error just seems to get smaller the more rand5() you use in that row. i think there is no solution without while() or if().
|
|
|
Re: NVidia Number Test
[Re: broozar]
#162318
10/22/07 21:23
10/22/07 21:23
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
EDIT: i was on the wrong page; ventilator and broozar made my explanation redundant.
julz
Last edited by JulzMighty; 10/22/07 21:28.
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: NVidia Number Test
[Re: JibbSmart]
#162319
10/22/07 23:05
10/22/07 23:05
|
Joined: Aug 2003
Posts: 7,440 Red Dwarf
Michael_Schwarz
Senior Expert
|
Senior Expert
Joined: Aug 2003
Posts: 7,440
Red Dwarf
|
what about: Code:
int rand7() { int answer = rand(5); answer = (answer<7)?answer+(rand5()-3):answer-rand(5); return (answer>0)?answer:answer+rand(5); }
?
"Sometimes JCL reminds me of Notch, but more competent" ~ Kiyaku
|
|
|
Re: NVidia Number Test
[Re: Doug]
#162320
10/23/07 01:27
10/23/07 01:27
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
DELETED: Sorry, one of my "friends" thought it would be funny to post random nonsense here.
Last edited by xXxGuitar511; 10/23/07 02:15.
xXxGuitar511 - Programmer
|
|
|
Re: NVidia Number Test
[Re: ventilator]
#162321
10/23/07 05:49
10/23/07 05:49
|
Joined: Jul 2006
Posts: 503 Australia
adoado
OP

User
|
OP

User
Joined: Jul 2006
Posts: 503
Australia
|
Quote:
doug, this way the probabilites aren't equal. see julzmighty's explanation. and you made a small mistake. after -7 the range is 0..28.
Code:
(rand5()+rand5()+rand5()+rand5()+rand5() - 2) / 3 gives this distribution after 1 million runs: {1: 6864, 2: 72170, 3: 243728, 4: 355145, 5: 243124, 6: 72255, 7: 6714}
did anyone have a thought about the one i posted earlier? Code:
(rand5() + 5*rand5() + 25*rand5() + 125*rand5() + 625*rand5() + 3125*rand5() + 15625*rand5() - 19531) % 7) + 1 is there some hidden flaw? the result seems to be correct: {1: 143263, 2: 142785, 3: 142579, 4: 142533, 5: 143609, 6: 142520, 7: 142711}
It looks like your method returns fairly even probabilities for each number to occur? Whats wrong with this one?
|
|
|
|