由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - how to generate 1 to 100k random integer numbers without zeros?
相关主题
请教一个sas问题菜鸟问个sas得问题,关于分数组
SAS,如何从一个大的dataset里面提取部分记录proc sql: find 4 highest and mean, median
Help for beginner of Macro如何在1,2,3,4,5中随机选出2个数来?
[合集] how to randomly draw 10% sample from a data set?In sas, how do you randomly pick 10 numbers out of 29?
请教一个SAS里面用随机数的问题proc sql如何随机选择数据。ranuni
SAS random number generatior该怎么用呀?求一个简单点的方法写一段SAS
ASK FOR ONE SAS QUESTIONHelp on understanding how to Creating a Random Sample without Replacement
请教如何用SAS处理这个RANDOM SAMPLING的问题Approximate random sample
相关话题的讨论汇总
话题: 100000话题: ranuni话题: integer话题: random话题: numbers
进入Statistics版参与讨论
1 (共1页)
j******n
发帖数: 2206
1
I use this formula
random_number=int(ranuni(0)*100000);
but it will give me 0, I don't want 0. if I add 1 to this formula,the
integer range will be 1 to 100001, which is alo not what I want.
I want exactly random integer numbers ranging from 1 to 100000.
Does anybody have an idea?
D******n
发帖数: 2836
2
0<=ranuni(0)<=1
0<=int(ranuni(0)*100000)<=100000
1<=int(ranuni(0)*100000)+1<=100001
however the probability of getting 100001 = 0
usually u can sub the first ineq with 0
s******r
发帖数: 1524
3
int(ranuni(0)*99999)+1; ?

【在 j******n 的大作中提到】
: I use this formula
: random_number=int(ranuni(0)*100000);
: but it will give me 0, I don't want 0. if I add 1 to this formula,the
: integer range will be 1 to 100001, which is alo not what I want.
: I want exactly random integer numbers ranging from 1 to 100000.
: Does anybody have an idea?

f***a
发帖数: 329
4
Rcode:
ceiling(runif(1)*100000)
j******n
发帖数: 2206
5
thanks guys, they are all good ways.
真是晕了,这些方法都想不到。
谢拉
P****D
发帖数: 11146
6
嗯,习惯用这个。

【在 s******r 的大作中提到】
: int(ranuni(0)*99999)+1; ?
j******n
发帖数: 2206
7
来看看别人的讨论,very interesting,大家有兴趣的话,可以继续讨论一下。多谢了。
You could multiply by 99999 and add 1 as suggested in the Language
Reference.
You do realize that your variable will contain a particular integer
whenever ranuni returns a value in the range
[integer/100000,integer/100000). For example it will contain 52 for
any value from .00052 to .0005299999999999. However, it will contain
100000 only when ranuni returns 1.0 exactly. Your integer
distribution will not be uniform.
You would probably be better
j******n
发帖数: 2206
8
another one:
PROC PLAN can produce a random permutation of the values 1-100000;
there will be no zero.
proc plan seed=1091883594;
factors r=100000 / noprint;
output out=r;
run;
proc print data=r(obs=100);
run;
proc print data=r(where=(r=0));
run;
j******n
发帖数: 2206
9
when i run int(ranuni(0))*100000 的时候,我得到了起码两个zero,说明0和1还是
可能有的,所以
int(ranuni(0))*100000+1可能还是不太对。

【在 D******n 的大作中提到】
: 0<=ranuni(0)<=1
: 0<=int(ranuni(0)*100000)<=100000
: 1<=int(ranuni(0)*100000)+1<=100001
: however the probability of getting 100001 = 0
: usually u can sub the first ineq with 0
j******n
发帖数: 2206
10
ceil(0)还是0吧?
不知道rcode里面结果是什么

【在 f***a 的大作中提到】
: Rcode:
: ceiling(runif(1)*100000)

相关主题
SAS random number generatior该怎么用呀?菜鸟问个sas得问题,关于分数组
ASK FOR ONE SAS QUESTIONproc sql: find 4 highest and mean, median
请教如何用SAS处理这个RANDOM SAMPLING的问题如何在1,2,3,4,5中随机选出2个数来?
进入Statistics版参与讨论
D******n
发帖数: 2836
11
first, understand int ,floor and ceiling function
second, draw a diagram and see what happen.
o****o
发帖数: 8077
12
%let n=100000;
%let seed=972675;
data _null_;
array _base{&n} p1-p&n;
retain seed &seed;
_prob=1/&n;
do _j=1 to dim(_base); _base[_j]=_prob; end;
chksum=sum(of p1-p&n);
call rantbl(seed, of p1-p&n, rv);
put chksum= rv=;
run;
not so efficient comparing to PROC PLAN but should be very handy when you
need one rv on the fly

了。

【在 j******n 的大作中提到】
: 来看看别人的讨论,very interesting,大家有兴趣的话,可以继续讨论一下。多谢了。
: You could multiply by 99999 and add 1 as suggested in the Language
: Reference.
: You do realize that your variable will contain a particular integer
: whenever ranuni returns a value in the range
: [integer/100000,integer/100000). For example it will contain 52 for
: any value from .00052 to .0005299999999999. However, it will contain
: 100000 only when ranuni returns 1.0 exactly. Your integer
: distribution will not be uniform.
: You would probably be better

p********a
发帖数: 5352
13
ranuni(0) could be 0 or 1? I thought it is something between 0 and 1 but not
equal to 0 or 1
D******n
发帖数: 2836
14
exactly
D******n
发帖数: 2836
15
I think lz is confused by two different situations, the first is 0 the second one is 0<= int(rand)
p********a
发帖数: 5352
16
Then what is the best way to get random numbers between 1 and N?
f***a
发帖数: 329
17
From the description of "runif()"
"runif will not generate either of the extreme values unless max = min or
max-min is small compared to min, and in particular not for the default
arguments."
It seems 0 won't be generated, so ceiling(runif(1)*N) should works OK.

【在 j******n 的大作中提到】
: ceil(0)还是0吧?
: 不知道rcode里面结果是什么

1 (共1页)
进入Statistics版参与讨论
相关主题
Approximate random sample请教一个SAS里面用随机数的问题
用SAS sampling的一个问题SAS random number generatior该怎么用呀?
如何用SAS 生成一个组合变量?ASK FOR ONE SAS QUESTION
[Teradata] How to randomly select one observation from each group?请教如何用SAS处理这个RANDOM SAMPLING的问题
请教一个sas问题菜鸟问个sas得问题,关于分数组
SAS,如何从一个大的dataset里面提取部分记录proc sql: find 4 highest and mean, median
Help for beginner of Macro如何在1,2,3,4,5中随机选出2个数来?
[合集] how to randomly draw 10% sample from a data set?In sas, how do you randomly pick 10 numbers out of 29?
相关话题的讨论汇总
话题: 100000话题: ranuni话题: integer话题: random话题: numbers