1 registered members (TipmyPip),
18,633
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: NVidia Number Test
[Re: adoado]
#162323
10/23/07 09:00
10/23/07 09:00
|
Joined: May 2002
Posts: 7,441
ventilator
Senior Expert
|
Senior Expert
Joined: May 2002
Posts: 7,441
|
Quote:
It looks like your method returns fairly even probabilities for each number to occur? Whats wrong with this one?
yes, it works quite well. but since the number isn't (and never will be like julzmighty said) dividable by 7 it's not 100% correct but the error just will get smaller the more rand5() you add. with 7 rand5() the error already is very small though.
|
|
|
Re: NVidia Number Test
[Re: lostclimate]
#162324
10/23/07 09:26
10/23/07 09:26
|
Joined: Jan 2003
Posts: 4,615 Cambridge
Joey
Expert
|
Expert
Joined: Jan 2003
Posts: 4,615
Cambridge
|
no equal distribution here, neither (@ lostclimate).
another problem is that when you have a look at the output of rand5 bit-wise you'll notice that the least significant bit is set 60% of time, bit 2 and 3 both 40% of time. for our rand7 we need (beginning at the least significant bit) p0=4/7, p1=4/7, p2=4/7. now try combining the first probabilities to retreive the second ones... you'll notice that it's impossible since x/7 is a prime fraction which can't be the result of a multiplication without another seven-fraction (i don't know the word in english, i hope you get my point). (in fact, not with an and, an or or an xor, since all outcome-probabilities are just additions or multiplications). so forget about combining the results of rand5 bitwise.
i tend to think that if you want no predictability (wrong in my example) and a perfectly equal distribution you'll need at least one if-branch.
joey.
Last edited by Joey; 10/23/07 09:29.
|
|
|
Re: NVidia Number Test
[Re: Joey]
#162325
10/23/07 12:02
10/23/07 12:02
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
Quote:
i tend to think that if you want no predictability (wrong in my example) and a perfectly equal distribution you'll need at least one if-branch.
or while loop but yeah, you're right. and i reckon an if-branch is friendlier than a while-loop, because theoretically the while loop could wait forever (at least in my case, though as mentioned earlier technically a computer would never allow that with its random lookup table).
ventilator's is accurate enough for anyone's purposes (if you're really fussy, add more powers of 5, if you know what i mean), but nVidia's rules may not have much leeway.
@anyone adding more suggestions: if you add any rand5()'s together without multiplying them to keep them out of each other's range, you will almost definitely suffer from dice-syndrome (i don't know if that's a real expression; probably not). keep an eye out for that. ventilator's mentioned at least a few times that this is a problem.
julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: NVidia Number Test
[Re: JibbSmart]
#162326
10/23/07 21:42
10/23/07 21:42
|
Joined: Nov 2003
Posts: 698 England, UK
Aaron_H
User
|
User
Joined: Nov 2003
Posts: 698
England, UK
|
I'd like to post a suggestion, even though I'm new to programming (and I've been doing Java which is slightly different)... (Sorry if the syntax is wrong) Just off the top of my head: Code:
int rand7(){ int a = rand5()*rand5(); // Min = 1, Max = 25 while (7<a<1) { int b = a - rand5()*rand5(); // If a = 1 => b = -24 to 0. If a = 25 => b = 0 to 24.. } a = b; }
I had to include a second variable, since I'm not sure how C++ would cope with; a = a - rand5()*rand5(); And I'm not sure how to get that function to return, so anyway, the final answer is stored in b or a. Anyone that knows more about C++ is welcome to tidy up/comment on the code.
Last edited by Aaron_H; 10/23/07 23:13.
|
|
|
Re: NVidia Number Test
[Re: Aaron_H]
#162327
10/23/07 22:29
10/23/07 22:29
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
yes, a = a - rand5()*rand5(); is allowed in C++ and values are returned simply by: Code:
return name_of_variable;
now, in your while loop 'a' doesn't actually get changed, so making "b = a" at the end is just going to make "b = whatever 'a' was at the beginning". and since 'a' doesn't change, if the condition was true (which it won't be, as i explain later), it would be an infinite loop. also, you don't need to have "int" in front of each reference; in fact you aren't allowed, because then it tries to declare another integer of the same name. basically what i mean is that last line should be "b = a;", not "int b = a;". another thing is the "7<a<1" -- that means "seven is less than 'a' which is less than one", but since 7>1, that will never be true. additionally, i don't actually know if C++ would handle a two-part comparison like that. i think i would normally do "((1<a)&&(a<7))", but "(1<a<7)" might work. i've just never tried. and lastly, rand5()*rand5() won't deal with every number between 1 and 25, because some are primes (7, 11, 13, 17, 19, 23), and some just won't be reached by multiplying two numbers between 1-5, even if they aren't primes (such as 18 and 24). the numbers that you DO get have unequal probability; for example, you can only obtain a 25 by getting 5*5, but you can obtain 4 by getting 1*4, 4*1, and 2*2. and before i go, don't take this the wrong way, like i'm picking apart your code. i know you said: Quote:
I'm new to programming (and I've been doing Java which is slightly different)
good onya for making an attempt anyway 
julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: NVidia Number Test
[Re: Joey]
#162329
10/23/07 23:02
10/23/07 23:02
|
Joined: Nov 2003
Posts: 698 England, UK
Aaron_H
User
|
User
Joined: Nov 2003
Posts: 698
England, UK
|
Ahh, thanks for the explainations guys. I knew what I was trying to get at.  I didn't realise C++ didn't like two part comparisions. (And JulzMighty, I don't take it the wrong way. Anything helps me learn.  ) I might give it another go when I've thought about it more. Maths is normally my strong point so I'm disappointed I forgot about the equal probabilities.  Edit: oh and the last line was supposed to be "a = b;" not "int b = a;.. I'll change the first post to suit.
Last edited by Aaron_H; 10/23/07 23:12.
|
|
|
Re: NVidia Number Test
[Re: Pappenheimer]
#162331
10/25/07 11:36
10/25/07 11:36
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
when you throw two dice, there are 12 possible answers, but not with equal probability, because there are actual 36 different combinations.
only 1 combination (1+1) will give "2", and only 1 combination (6+6) will give us "12", but 6 combinations (1+6, 2+5, 3+4, 4+3, 5+2, 6+1) can give us "7", so "7" is the most probable result.
i use the term "dice-syndrome" to describe adding different "equal-probability" events together to come up with an unequal-probability event, such as using rand5()+rand5().
julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
|