Acer Aspire AS5740-5255 Intel Core i3-330M 2.13GHz, 4GB DDR3, 320GB HDD, DVDRW, 15.6" Display, Windows 7 Home Premium 64-bit, Blue
o*d
2 楼
http://www.careercup.com/question?id=12426697 Given a random number generator say r(5) generates number between 1-5 uniformly at random , use it to in r(7) which should generate a random number between 1-7 uniformly at random. ===========solution: my solution is the same with this: >>>>>>>>> Let f() be the random function that returns a number between (1,5). Let g() = f() -1; then g is a function that returns a number between (0,4). Let h() = g()/4; then h is a function that returns a number between (0,1). Let i() = h()*6; then i is a function that returns a number between (0,6) Let j() = i() + 1; then j is a function that returns a number between (1,7). but careercup's thread:>>>>>>>>> int rand7() //random number from 1 - 7 { int r = 0; do { int a = rand(5) - 1; //uniformly at random from 0 to 4 int b = rand(5) - 1; //uniformly at random from 0 to 4 r = 5*b + a; //uniformly at random from 0 to 24 } while (r >= 21); // in this event, we have to roll again //postcondition of loop: we have a number uniformly at random between 0 and 20 return r % 7 + 1;
//there are 3 numbers in [0, 20] for each possible return value //so each has equal probability. } 我的答案有问题么?我觉得没有问题吧?
【在 n***l 的大作中提到】 : Acer Aspire AS5740-5255 Intel Core i3-330M 2.13GHz, 4GB DDR3, 320GB HDD, : DVDRW, 15.6" Display, Windows 7 Home Premium 64-bit, Blue
l*b
5 楼
你的答案不对。。。给的随机数发生器只得到整数。
【在 o***d 的大作中提到】 : http://www.careercup.com/question?id=12426697 : Given a random number generator say r(5) generates number between 1-5 : uniformly at random , use it to in r(7) which should generate a random : number between 1-7 uniformly at random. : ===========solution: : my solution is the same with this: : >>>>>>>>> : Let f() be the random function that returns a number between (1,5). : Let g() = f() -1; then g is a function that returns a number between (0,4). : Let h() = g()/4; then h is a function that returns a number between (0,1).
【在 o***d 的大作中提到】 : http://www.careercup.com/question?id=12426697 : Given a random number generator say r(5) generates number between 1-5 : uniformly at random , use it to in r(7) which should generate a random : number between 1-7 uniformly at random. : ===========solution: : my solution is the same with this: : >>>>>>>>> : Let f() be the random function that returns a number between (1,5). : Let g() = f() -1; then g is a function that returns a number between (0,4). : Let h() = g()/4; then h is a function that returns a number between (0,1).
【在 o***d 的大作中提到】 : http://www.careercup.com/question?id=12426697 : Given a random number generator say r(5) generates number between 1-5 : uniformly at random , use it to in r(7) which should generate a random : number between 1-7 uniformly at random. : ===========solution: : my solution is the same with this: : >>>>>>>>> : Let f() be the random function that returns a number between (1,5). : Let g() = f() -1; then g is a function that returns a number between (0,4). : Let h() = g()/4; then h is a function that returns a number between (0,1).