数组??
string r_string=''
for i=1 to 7
r_string+=string(rand_num[i])+' '
next
mle_1.text=r_string+' '
其中rand_num[i]是一个随机的整数数组,为什么第一个数总是 0 呢?
问题点数:20、回复次数:5Top
1 楼princelily(百合)回复于 2005-04-07 17:57:29 得分 5
你定义的rand_num[]数组是怎么初始化的,我知道Rand(n)函数是得到1到n之间的一个伪随机数。不知道你是怎么设定随机数的。嘿嘿Top
2 楼zengpeiwen(笑江)回复于 2005-04-07 18:04:14 得分 0
就rand(30)
假如
r_string=string(rand_num[i])+' '+r_string
则是最后一个为0
Top
3 楼fibbery(飞)(睡足了才能提高效率)回复于 2005-04-07 18:08:05 得分 5
先使用下面的函数:
Description
Initializes the random number generator so that the Rand function begins a new series of pseudorandom numbers.
Syntax
Randomize ( n )
Argument Description
n The starting value (seed) for the random number generator. When n is 0, PowerBuilder takes the seed from the system clock and begins a nonrepeatable sequence. A nonzero number generates a different but repeatable sequence for each seed value. n cannot exceed 32,767
Return value
Integer. If n is NULL, Randomize returns NULL. The return value is never used.
Usage
The sequence of numbers generated by repeated calls to the Rand function is a computer-generated pseudorandom sequence. You can use the Randomize function to initialize the random number generator with a value from the system clock, or some other changing value, so that the sequence is always different. For testing purposes, you can select a specific seed value, which you can reuse to make the pseudorandom sequence repeatable each time you run the application.
Include Randomize in the script for the Open event in the application.Top
4 楼fibbery(飞)(睡足了才能提高效率)回复于 2005-04-07 18:10:03 得分 5
先初始化随机数生成器,不然每次使用运行时所获得的随机数是一样的!Top
5 楼jiangxj()回复于 2005-04-08 09:04:24 得分 5
先设置
Randomize (0)
再做你的代码就行了
Randomize (0)表示用系统时间初始化随机数,由于时间总在变,故得到的随机数序列也不同Top




