由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
CS版 - 请教一道老面试题,谢谢
相关主题
About testing of uniform distributionfor PhD thesis by Songnian Zhou
谁知道 一致有限性 英语怎么翻? 谢了.把network跟DB、architecture结合起来?
PROOF -- Re: EE challenge CS[转载]普适计算方面的会议
Re: 请教一个 graph connectivity 的问题请教一个distribution之间的likelihood问题 (转载)
EM 算法想转学了,推荐几所春季入学的学校
懂scale-invariant field或者图像处理的朋友请看进来 (转载)Howard University recruiting (tenure-track)
what's more can we do in IR?Planet-lab mangement tools
怎样distribute "call for papers"搞通信网路哪个方向好找工作一些?
相关话题的讨论汇总
话题: int话题: rnd5话题: rnd话题: uniform
进入CS版参与讨论
1 (共1页)
b*******a
发帖数: 68
1
Given a function which produces a random integer in the range 1 to 5, write
a function which produces a random integer in the range 1 to 7.
s******e
发帖数: 285
2
jobhunting版考古

write

【在 b*******a 的大作中提到】
: Given a function which produces a random integer in the range 1 to 5, write
: a function which produces a random integer in the range 1 to 7.

z*****n
发帖数: 7639
3
int r5();
int rand7(){
return (int) (r5()+r5()+r5()+r5()+r5()+r5()+r5())/5;
}

write

【在 b*******a 的大作中提到】
: Given a function which produces a random integer in the range 1 to 5, write
: a function which produces a random integer in the range 1 to 7.

b*******a
发帖数: 68
4
I know, but I just could not find it... :-(

【在 s******e 的大作中提到】
: jobhunting版考古
:
: write

b*******a
发帖数: 68
5
JobHunting 2019 -- I am reading it....
2019 m ● [合集] 那个Google random generate 1-7的题怎么做啊(14.0k)
4/1326 heing
2006-11-11 mengt
01-08 23:14

【在 b*******a 的大作中提到】
: I know, but I just could not find it... :-(
j**********s
发帖数: 132
6
这样做是错滴,几个 uniform distribution 的 random variable 之和就不在是
uniform distribution 了。

【在 z*****n 的大作中提到】
: int r5();
: int rand7(){
: return (int) (r5()+r5()+r5()+r5()+r5()+r5()+r5())/5;
: }
:
: write

a***n
发帖数: 404
7
(rnd(5)+rnd(5)+rnd(5)+rnd(5)+rnd(5)+rnd(5)+rnd(5)) mod 7 ?

【在 j**********s 的大作中提到】
: 这样做是错滴,几个 uniform distribution 的 random variable 之和就不在是
: uniform distribution 了。

z*****n
发帖数: 7639
8
Oh, thanks for pointing out.
I will think of it again.

【在 j**********s 的大作中提到】
: 这样做是错滴,几个 uniform distribution 的 random variable 之和就不在是
: uniform distribution 了。

z*****n
发帖数: 7639
9
this is the same...

【在 a***n 的大作中提到】
: (rnd(5)+rnd(5)+rnd(5)+rnd(5)+rnd(5)+rnd(5)+rnd(5)) mod 7 ?
y**q
发帖数: 246
10
为什么要加那么多次?而不是直接7*rnd(5)?

【在 z*****n 的大作中提到】
: this is the same...
相关主题
懂scale-invariant field或者图像处理的朋友请看进来 (转载)for PhD thesis by Songnian Zhou
what's more can we do in IR?把network跟DB、architecture结合起来?
怎样distribute "call for papers"[转载]普适计算方面的会议
进入CS版参与讨论
a***n
发帖数: 404
11
请具体讲讲是个啥分布了? 。。。。 晕了

【在 j**********s 的大作中提到】
: 这样做是错滴,几个 uniform distribution 的 random variable 之和就不在是
: uniform distribution 了。

a***n
发帖数: 404
12
人家是 /5 ,我是 mod 7 这两个一样么?

【在 z*****n 的大作中提到】
: this is the same...
z*****n
发帖数: 7639
13
because you used the same Uniform distribution addition,
this part is critical.

【在 a***n 的大作中提到】
: 人家是 /5 ,我是 mod 7 这两个一样么?
z*****n
发帖数: 7639
14
two uniformly distributed variables added together,
say v=u1+u2, is not a uniform distribution variable,
in stead, it becomes a triangular distribution,
3 uniformly distributed variables added together will
produce a more complex distribution...
A simple example: u1 and u2 uniformly distributes in
1 and 2
u1 = u2 : 1(0.5) 2(0.5)
u1 + u2 : 2(0.25) 3(0.5) 4(0.25)

【在 a***n 的大作中提到】
: 请具体讲讲是个啥分布了? 。。。。 晕了
a***n
发帖数: 404
15
why the addition result is not uniform distribution? then what distribution?
...:(

【在 z*****n 的大作中提到】
: because you used the same Uniform distribution addition,
: this part is critical.

z*****n
发帖数: 7639
16
see my previous post :)

distribution?

【在 a***n 的大作中提到】
: why the addition result is not uniform distribution? then what distribution?
: ...:(

a***n
发帖数: 404
17
哦。多谢。我再想想看看有没有啥别的办法。。

【在 z*****n 的大作中提到】
: two uniformly distributed variables added together,
: say v=u1+u2, is not a uniform distribution variable,
: in stead, it becomes a triangular distribution,
: 3 uniformly distributed variables added together will
: produce a more complex distribution...
: A simple example: u1 and u2 uniformly distributes in
: 1 and 2
: u1 = u2 : 1(0.5) 2(0.5)
: u1 + u2 : 2(0.25) 3(0.5) 4(0.25)

a***n
发帖数: 404
18
got it~~ :)

【在 z*****n 的大作中提到】
: see my previous post :)
:
: distribution?

z*****n
发帖数: 7639
19
Ok, got a stupid way but gives uniform
distribution in (1,8), then for rnd7(), follow
the same way:
int rnd7(){
int k;
do{
k=rnd8();
}while(k==8);
return k;
}
int rnd8(void){
int k,h;
do{
k=rnd5();
}while(k==5);
do{
h=rnd5();
}while(h>2);
if(h==1) return k;
else return k+4;
}

【在 z*****n 的大作中提到】
: Oh, thanks for pointing out.
: I will think of it again.

z*****n
发帖数: 7639
20
here is the whole program with test code, my
result is (for 1 to 7)
143283
142313
143015
142959
142752
142532
143146
#include
#include
#include
#define rnd5() rand()%5+1
int rnd8(void);
void main(){
int a, b[5]={0,0,0,0,0}, c, d[8]={0,0,0,0,0,0,0,0};
srand(time(NULL));
for(a=0; a<100000; a++){
c=rnd5();
b[c-1]++;
}
for(a=0; a<5; a++) printf("%d\t", b[a]);
for(a=0; a<1000000; a++){


【在 z*****n 的大作中提到】
: Ok, got a stupid way but gives uniform
: distribution in (1,8), then for rnd7(), follow
: the same way:
: int rnd7(){
: int k;
: do{
: k=rnd8();
: }while(k==8);
: return k;
: }

a***n
发帖数: 404
21
sounds good!

【在 z*****n 的大作中提到】
: here is the whole program with test code, my
: result is (for 1 to 7)
: 143283
: 142313
: 143015
: 142959
: 142752
: 142532
: 143146
: #include

1 (共1页)
进入CS版参与讨论
相关主题
搞通信网路哪个方向好找工作一些?EM 算法
问个Matlab的问题 (转载)懂scale-invariant field或者图像处理的朋友请看进来 (转载)
gold mine herewhat's more can we do in IR?
问个distributed protocol的问题怎样distribute "call for papers"
About testing of uniform distributionfor PhD thesis by Songnian Zhou
谁知道 一致有限性 英语怎么翻? 谢了.把network跟DB、architecture结合起来?
PROOF -- Re: EE challenge CS[转载]普适计算方面的会议
Re: 请教一个 graph connectivity 的问题请教一个distribution之间的likelihood问题 (转载)
相关话题的讨论汇总
话题: int话题: rnd5话题: rnd话题: uniform