Hilbert's Hotel

Diskussionsforum zur Unendlichkeit: Theismus, Atheismus, Primzahlen, Unsterblichkeit, das Universum...
Discussing Infinity: theism and atheism, prime numbers, immortality, cosmology, philosophy...

Gamestudio Links
Zorro Links
Newest Posts
freewhyblogelsewhere
by 9489cpjf. 06/03/24 06:06
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,321 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19056 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 7 1 2 3 4 5 6 7
Re: NVidia Number Test [Re: JibbSmart] #162293
10/20/07 14:31
10/20/07 14:31
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
i am not sure about the solutions so far since i am lazy and it takes too long to fully think them through. they all seem wrong to me at a first glance.

i came up with something pretty simple now:
Code:
int rand7()
{
return (rand5()+rand5()+rand5()+rand5()+rand5() - 2) / 3;
}



the five rand5() give the range 5..25, after -2 the range will be 3..23, after the integer division by 3 it will be 1..7! or did i miss something?

Re: NVidia Number Test [Re: ventilator] #162294
10/20/07 22:40
10/20/07 22:40
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
when i woke up this morning i realised that mine's still wrong -- it still suffers from dice syndrome.

ventilator, as elegant as your solution is, it suffers from the same problem.
there are, of course, 7 different possible results, but there are 5*5*5*5*5 = 3125 different ways to get those results. 7 is not a factor of 3125. of course, that's only a little sign that something does NOT have 7 results with equal probability. if it were divisible by 7, it wouldn't necessarily have avoided the problem i'm about to explain as follows:

a "1" will be returned whenever rand5()+...rand5()-2 < 6 (if i'm right in assuming that type conversion to integer doesn't round, but instead truncates the number). this will happen when rand5()+...rand5() < 8. now, it would take way too long to count out the number of combinations. but, it does require a result between 5-7, and that's the bottom range of this whole process. 5 can only be obtained the following way:
1+1+1+1+1
6 is much more likely to be obtained:
1+1+1+1+2
1+1+1+2+1
1+1+2+1+1
1+2+1+1+1
2+1+1+1+1
and as we get closer to the middle ((25-5+1)/2+5=15.5, which should be exactly halfway between 5 and 25) we get more possible combinations, and so the number with the highest probability of being obtained is (15-2)/3 = ~4, (16-2)/3 = ~4, because its rand5()+...+rand5() results need to be between 14-16, which have the highest number of combinations attributed to them.

which makes sense, of course, because 4 is exactly halfway between 1 and 7.

this basically explains the "dice syndrome" i mentioned earlier, which we're all yet to overcome.

julz


Formerly known as JulzMighty.
I made KarBOOM!
Re: NVidia Number Test [Re: JibbSmart] #162295
10/20/07 23:02
10/20/07 23:02
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
i've got it:

rand5() + rand5()*5 has a result between 6 and 30, with only one possible combination for each answer <-- that's really nice, but what can we do with the 25 different results?

we can take just 21 of them. if we get higher than the 21st result, just do it again.
Code:
int rand7()
{
int answer = 27;
while(answer>26)
answer = rand5() + rand5()*5;
return (answer-5)%7+1;
}



i think that's it.

julz

edited to return the answer

Last edited by JulzMighty; 10/21/07 00:50.

Formerly known as JulzMighty.
I made KarBOOM!
Re: NVidia Number Test [Re: JibbSmart] #162296
10/20/07 23:33
10/20/07 23:33
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
you are right! mine doesn't give equal probabilites. here is a simple python test script:
Code:
import random

def rand5():
return int((random.random() * 5) + 1)

##def rand7():
## return (rand5()+rand5()+rand5()+rand5()+rand5() - 2) / 3

def rand7():
answer = 27
while answer > 26:
answer = rand5() + rand5() * 5
return (answer - 5) % 7 + 1

count = {}
for i in range(1000000):
r = rand7()
if count.has_key(r):
count[r] += 1
else:
count[r] = 1

print count

your version works! but is a version without while or if possible?



<edit>hm... i am not sure but this one seems to work:
Code:
def rand7():
return ((rand5() +
5*rand5() +
25*rand5() +
125*rand5() +
625*rand5() +
3125*rand5() +
15625*rand5() - 19531) % 7) + 1

i only found this with some trial and error though! </edit>

Re: NVidia Number Test [Re: ventilator] #162297
10/21/07 00:58
10/21/07 00:58
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
good question -- branches and loops are ugly!

if we can find a power of 5 that is divisible by 7, then my version could be changed a little to do without the while-loop. the trouble is that there aren't any

i'm glad it works though i have loads of study to do for tomorrow and i couldn't justify taking the time to test it. would you mind explaining how your test works? i don't know anything about python, so that last bit is gibberish to me. is it counting how many of each number is returned?

julz


Formerly known as JulzMighty.
I made KarBOOM!
Re: NVidia Number Test [Re: JibbSmart] #162298
10/21/07 07:08
10/21/07 07:08
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
Quote:

*2 makes the "1" impossible




oops ..it cant work anyway becasue of the progression of the products.. oh well.. i am not good at this kind of thing.


Sphere Engine--the premier A6 graphics plugin.
Re: NVidia Number Test [Re: Matt_Aufderheide] #162299
10/21/07 22:25
10/21/07 22:25
Joined: Aug 2003
Posts: 7,439
Red Dwarf
Michael_Schwarz Offline
Senior Expert
Michael_Schwarz  Offline
Senior Expert

Joined: Aug 2003
Posts: 7,439
Red Dwarf
Quote:

Code:
int rand7()
{
float r7=0;

for(int i=0; i<7; i++)
{
r7+=rand5();
}

return int((r7/7)*2);
}



This ought to work unless I'm deluding myself.. however its probably not very elegant.. like all my code




you said earlier that this wouldnt work because *2 makes 1 impossible, what about if we modificate it a bit like this:

Code:
int rand7()
{
float r7=0;

for(int i=0; i<8; i++)
{
r7+=rand5();
}

return int(((r7/8)*2)-1);
}



wouldn't that work?


"Sometimes JCL reminds me of Notch, but more competent" ~ Kiyaku
Re: NVidia Number Test [Re: Michael_Schwarz] #162300
10/22/07 16:19
10/22/07 16:19
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
i tend to think it's not possible at all since both 5 and 7 are prime numbers and rand5 can't return 0.

edit: ok, i found a way... at least all numbers are equally probable here. not very elegant, though.
Code:
short int rand7()
{
short int temp = 0;

for (int i = 0; i < 8; i ++) {
temp += rand5()-1;
}

if (temp == 32) {
return rand7();
}

return temp/4+1;
}



Last edited by Joey; 10/22/07 16:27.
Re: NVidia Number Test [Re: Joey] #162301
10/22/07 16:54
10/22/07 16:54
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
no, the latest two both don't give equal probabilities and i think the range of returned numbers is wrong too.

Re: NVidia Number Test [Re: ventilator] #162302
10/22/07 17:53
10/22/07 17:53
Joined: Jul 2000
Posts: 8,973
Bay Area
Doug Offline
Senior Expert
Doug  Offline
Senior Expert

Joined: Jul 2000
Posts: 8,973
Bay Area
I'm must be missing something because this sounds too easy:

Code:

ans = (((rand5()-1) / 4f)*6f) + 1;



You could reduce this down, but I left it long so you can follow the logic.

Code:

(rand5()-1) -> random number 0-4
/ 4 -> random number 0-1
* 6 -> random number 0-6
+ 1 -> random number 1-7




Conitec's Free Resources:
User Magazine || Docs and Tutorials || WIKI
Page 2 of 7 1 2 3 4 5 6 7

Moderated by  jcl, Lukas, old_bill, Spirit 

Kompaktes W�rterbuch des UnendlichenCompact Dictionary of the Infinite


Powered by UBB.threads™ PHP Forum Software 7.7.1