帮我看一下,为什么生成随机密码只执行一次?

sunlijun 2003-03-23 08:01:55
我用游标做生成随机密码,有20条记录,密码都更新了,但密码值一样!
请教是何原因?

long i, ll_loop
string ls_result,ls_mima
int li_num,l_x
boolean lb_continue
long ls_rowcount

select count(*) into:ls_rowcount from j_renyuan where j_renyuan.hangming='hangmin';
hpb_1.maxposition=ls_rowcount
l_x=1
declare mima_cur cursor for select j_renyuan.mima from j_renyuan where j_renyuan.hangming='201';
open mima_cur;

lb_continue=True
do while lb_continue=True
FETCH mima_cur
INTO:ls_mima;

If sqlca.sqlcode=0 Then
// 生成随机密码
ll_loop = 8

for i = 1 to ll_loop

li_num = Rand(122)

choose case li_num
case 48 to 57
ls_result = ls_result + char(li_num) //数字
case 65 to 90
ls_result = ls_result + char(li_num) //大写字母
case 97 to 122
ls_result = ls_result + char(li_num) //小写字母
case else
ll_loop++
end choose
next
//密码生成完毕
//messagebox('',ls_result)
UPDATE j_renyuan SET j_renyuan.mima=:ls_result
WHERE CURRENT of mima_cur;
hpb_1.position=l_x
l_x=l_x+1
Else
lb_continue=False
parent.title="生成结束!"
End If
LOOP
commit;
close mima_cur;
...全文
64 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunlijun 2003-03-25
  • 打赏
  • 举报
回复
还是不太好用,重复得太多!
jimmyxc 2003-03-24
  • 打赏
  • 举报
回复
错了,是li_num = mod(xx,122)
jimmyxc 2003-03-24
  • 打赏
  • 举报
回复
随机一个更大的值,rand(9999999),long xx=rand(999999)/13+integer(String(Now(), "hh")) * integer(String(Now(), "ss"))然后mod(xx,12)
我就不信你还能取到一样的密码
tchatcha 2003-03-24
  • 打赏
  • 举报
回复
long i, ll_loop
string ls_result,ls_mima
int li_num,l_x
boolean lb_continue
long ls_rowcount

select count(*) into:ls_rowcount from j_renyuan where j_renyuan.hangming='hangmin';
hpb_1.maxposition=ls_rowcount
l_x=1
declare mima_cur cursor for select j_renyuan.mima from j_renyuan where j_renyuan.hangming='201';
open mima_cur;

lb_continue=True
do while lb_continue=True
FETCH mima_cur
INTO:ls_mima;

If sqlca.sqlcode=0 Then
// 生成随机密码
ll_loop = 8
i=1
ls_result=' '
for i = 1 to ll_loop

li_num = Rand(122)

choose case li_num
case 48 to 57
ls_result = ls_result + char(li_num) //数字
case 65 to 90
ls_result = ls_result + char(li_num) //大写字母
case 97 to 122
ls_result = ls_result + char(li_num) //小写字母
case else
ll_loop++
end choose
next
//密码生成完毕
//messagebox('',ls_result)
UPDATE j_renyuan SET j_renyuan.mima=:ls_result
WHERE CURRENT of mima_cur;
hpb_1.position=l_x
l_x=l_x+1
Else
lb_continue=False
parent.title="生成结束!"
End If
LOOP
commit;
close mima_cur;
jimmyxc 2003-03-24
  • 打赏
  • 举报
回复
奇怪,我把你的循环板下来出来的都不一样列,UP,知道原因告诉我
huangxinru 2003-03-24
  • 打赏
  • 举报
回复
你的变量ls_result在循环体中没有清空,而列的长度有限,所以每次均截取了前面的字符串
sunlijun 2003-03-24
  • 打赏
  • 举报
回复
不行还是一样!
huangxinru 2003-03-24
  • 打赏
  • 举报
回复
在这段程序的循环之前,加上语句randomize(0)
xirumin 2003-03-23
  • 打赏
  • 举报
回复
randomize()函数是随机种子,一般以时间做为种子。这样保证每次的随机数序列值不一样, 用rand产生的随机数也不一样。用法可看帮助
sunlijun 2003-03-23
  • 打赏
  • 举报
回复
请问怎么用Randomize(n)?

我直接替换rand(),程序好像死循环,没有响应!
dotnba 2003-03-23
  • 打赏
  • 举报
回复
因为Rand产生的是伪随即数序列,所以最好使用Randomize ( n ) Initializes the random number generator so that the Rand function begins a new series of pseudorandom numbers.
sunlijun 2003-03-23
  • 打赏
  • 举报
回复
还是结不了贴!没搞懂!
jimmyxc 2003-03-23
  • 打赏
  • 举报
回复
Rand(122) 后面多写些东西撒,*时间,/日期,什么都可以越乱越好,这样重复的机会才不大
sunlijun 2003-03-23
  • 打赏
  • 举报
回复
那位大侠有时间,帮我看看,我的程序需要改些什么!
sunlijun 2003-03-23
  • 打赏
  • 举报
回复
看完帮助了,一无所获!

1,075

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧