| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6392 人关注过本帖
标题:[求助]一个程序,想破头了都不知该怎么编!
只看楼主 加入收藏
ioriliao
Rank: 7Rank: 7Rank: 7
来 自:广东
等 级:贵宾
威 望:32
帖 子:2829
专家分:647
注 册:2006-11-30
收藏
得分:0 

我只发产生随机数的源码..至于怎么控制不会产生相同的字符串...就先不发..!
Dim cd As Collection

Dim Str() As Variant
Dim okStr(9999) As String
Dim rndInt1 As Integer
Dim rndInt2 As Integer
Dim rndInt3 As Integer
Dim rndInt4 As Integer
Dim rndInt5 As Integer
Dim rndInt6 As Integer
Dim rndInt7 As Integer
Dim rndInt8 As Integer
Dim rndInt9 As Integer
Dim rndInt10 As Integer
Dim rndInt11 As Integer
Dim rndInt12 As Integer
Dim rndInt13 As Integer
Dim rndInt14 As Integer
Dim rndInt15 As Integer
Dim rndInt16 As Integer


Private Sub Form_Load()
Randomize

Str = Array("q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s", "d", "f", "g", "h", "j", "k", "l", _
"z", "x", "c", "v", "b", "n", "m", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "A", "S", "D", _
"F", "G", "H", "J", "K", "L", "Z", "X", "C", "V", "B", "N", "M", "0", "1", "2", "3", _
"4", "5", "6", "7", "8", "9")
End Sub

Private Sub Command1_Click()
Randomize
Set cd = New Collection
For i = 0 To 9999

rndInt1 = Int(Rnd * 62)
rndInt2 = Int(Rnd * 62)
rndInt3 = Int(Rnd * 62)
rndInt4 = Int(Rnd * 62)
rndInt5 = Int(Rnd * 62)
rndInt6 = Int(Rnd * 62)
rndInt7 = Int(Rnd * 62)
rndInt8 = Int(Rnd * 62)
rndInt9 = Int(Rnd * 62)
rndInt10 = Int(Rnd * 62)
rndInt11 = Int(Rnd * 62)
rndInt12 = Int(Rnd * 62)
rndInt13 = Int(Rnd * 62)
rndInt14 = Int(Rnd * 62)
rndInt15 = Int(Rnd * 62)
rndInt16 = Int(Rnd * 62)
If i < 5000 Then
str1 = (Str(rndInt1)) & (Str(rndInt2)) & (Str(rndInt3)) & (Str(rndInt4)) _
& (Str(rndInt5)) & (Str(rndInt6)) & (Str(rndInt7)) & (Str(rndInt8)) _
& (Str(rndInt9)) & (Str(rndInt10)) & (Str(rndInt11)) & (Str(rndInt12)) _
& (Str(rndInt13)) & (Str(rndInt14)) & (Str(rndInt15)) & (Str(rndInt16)) _
& "#100"

cd.Add str1
ElseIf i >= 5000 And i <= 7999 Then

str1 = (Str(rndInt1)) & (Str(rndInt2)) & (Str(rndInt3)) & (Str(rndInt4)) _
& (Str(rndInt5)) & (Str(rndInt6)) & (Str(rndInt7)) & (Str(rndInt8)) _
& (Str(rndInt9)) & (Str(rndInt10)) & (Str(rndInt11)) & (Str(rndInt12)) _
& (Str(rndInt13)) & (Str(rndInt14)) & (Str(rndInt15)) & (Str(rndInt16)) _
& "#200"
cd.Add str1
Else
str1 = (Str(rndInt1)) & (Str(rndInt2)) & (Str(rndInt3)) & (Str(rndInt4)) _
& (Str(rndInt5)) & (Str(rndInt6)) & (Str(rndInt7)) & (Str(rndInt8)) _
& (Str(rndInt9)) & (Str(rndInt10)) & (Str(rndInt11)) & (Str(rndInt12)) _
& (Str(rndInt13)) & (Str(rndInt14)) & (Str(rndInt15)) & (Str(rndInt16)) _
& "#500"
cd.Add str1
End If

Randomize

For i = 1 To cd.Count

rndInt16 = Int(Rnd * cd.Count + 1)
gg = gg & cd.Item(rndInt16) & vbCrLf


cd.Remove (rndInt16)


Form1.Caption = cd.Count
Next
RichTextBox1.Text = gg


/images/2011/147787/2011051411021524.jpg" border="0" />
2007-04-10 16:44
freeforever
Rank: 4
等 级:业余侠客
威 望:3
帖 子:368
专家分:201
注 册:2005-11-2
收藏
得分:0 

我刚才重启机器了,一个哥们向我要VFP的图书馆管理系统代码,我去找了,没找到,谁能帮我呀

我的代码就简单了,看吧:
Option Explicit

Const MAX100 = 5
Const MAX200 = 3
Const MAX500 = 2

Private Sub Form_Load()
Dim strTime As String, strALl As String
strTime = Time()
Dim i As Integer, j As Integer, k As Integer
Dim intTmp As Integer, intLenSTRALL As Integer
Dim cnt100 As Integer, cnt200 As Integer, cnt500 As Integer
strALl = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Randomize Time
intLenSTRALL = Len(strALl)
Dim strTmp As String
Open App.Path & "\Test.txt" For Output As #1
For i = 1 To 1000
cnt100 = 0: cnt200 = 0: cnt500 = 0
For j = 1 To 10
For k = 1 To 16
intTmp = Rnd * 1000 Mod 61 + 1
Print #1, Mid(strALl, intTmp, 1);
Next k
intTmp = intTmp Mod 10
If (intTmp Mod 2 = 0) And cnt100 < MAX100 Then
Print #1, "#100": cnt100 = cnt100 + 1
ElseIf (intTmp Mod 4 = 1) And cnt200 < MAX200 Then
Print #1, "#200": cnt200 = cnt200 + 1
ElseIf (intTmp Mod 4 = 3) And cnt500 < MAX500 Then
Print #1, "#500": cnt500 = cnt500 + 1
ElseIf (MAX100 - cnt100) > (MAX200 - cnt200) And cnt100 < MAX100 Then
Print #1, "#100": cnt100 = cnt100 + 1
ElseIf (MAX200 - cnt200) > (MAX500 - cnt500) And cnt200 < MAX200 Then
Print #1, "#200": cnt200 = cnt200 + 1
ElseIf (MAX500 - cnt500) > (MAX100 - cnt100) And cnt500 < MAX500 Then
Print #1, "#500": cnt500 = cnt500 + 1
ElseIf (cnt100 < MAX100) Then
Print #1, "#100": cnt100 = cnt100 + 1
ElseIf (cnt200 < MAX200) Then
Print #1, "#200": cnt200 = cnt200 + 1
ElseIf (cnt500 < MAX500) Then
Print #1, "#500": cnt500 = cnt500 + 1
End If
Next j
Next i
Close #1
MsgBox strTime & "-" & Time()
End
End Sub


其实我也很无聊!
2007-04-10 16:50
ioriliao
Rank: 7Rank: 7Rank: 7
来 自:广东
等 级:贵宾
威 望:32
帖 子:2829
专家分:647
注 册:2006-11-30
收藏
得分:0 
代码是少..切不简单...
太多的for和if的程序不好读啊!

/images/2011/147787/2011051411021524.jpg" border="0" />
2007-04-10 16:53
Joforn
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:1242
专家分:122
注 册:2007-1-2
收藏
得分:0 
我回家把电脑弄好后就发上来。我的方法和你们不太一样

VB QQ群:47715789
2007-04-10 16:54
freeforever
Rank: 4
等 级:业余侠客
威 望:3
帖 子:368
专家分:201
注 册:2005-11-2
收藏
得分:0 
解释一下我的程序,三生循环里的最内的是用来产生一条记录(16个字符),第二重生成一组(10=2+3+5)个记录,后面的IF语句是把一组随机分类写上后缀,第一重循环用来生成1000组(也就是10000)条记录,呼呼......就这样搞定了!

其实我也很无聊!
2007-04-10 16:58
freeforever
Rank: 4
等 级:业余侠客
威 望:3
帖 子:368
专家分:201
注 册:2005-11-2
收藏
得分:0 
看了ioriliao的程序了,我没见过Collection,呵呵,你的程序耗时间就在后面的随机安排后缀出现的次序上了,不知道Collection在删除时是怎样工作的,你给介绍一下吧.

我的程序不好明白的就在那组IF语句了,其实就像满酒一样:
三个大小不一样的杯子,随机往一个杯子里倒一滴;当选中的杯子满了时,选另外两个相对更空的杯子;当二个杯子满了,就只能往第三个杯子里倒了.我之前的程序在文件尾会出现同一后缀的大量连续记录就是这个只剩第三杯的原因,改进后是分成两个循环,即把三个杯子都缩小1000倍,在文件里就看不出问题了,呵呵,好累.....

其实我也很无聊!
2007-04-10 17:07
Joforn
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:1242
专家分:122
注 册:2007-1-2
收藏
得分:0 

你们的产生十万条大概要多少时间?
看了一下你们都是由十六个字符串最后组成一个字符串的,估计很费时吧?


VB QQ群:47715789
2007-04-10 17:16
freeforever
Rank: 4
等 级:业余侠客
威 望:3
帖 子:368
专家分:201
注 册:2005-11-2
收藏
得分:0 

不到4秒,我的不存在这问题,直接写入文件里的,没有字串连接操作


其实我也很无聊!
2007-04-10 17:39
Joforn
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:1242
专家分:122
注 册:2007-1-2
收藏
得分:0 
但你的一条字符串写了17次文件

VB QQ群:47715789
2007-04-10 17:47
freeforever
Rank: 4
等 级:业余侠客
威 望:3
帖 子:368
专家分:201
注 册:2005-11-2
收藏
得分:0 
??不可能吧,把你的验证程序代码发上来看看

其实我也很无聊!
2007-04-10 18:03
快速回复:[求助]一个程序,想破头了都不知该怎么编!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017868 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved