Private Sub Command1_Click()
Dim s$
Dim i As Single, sng1 As Single
Dim j%
On Error resume next'当数据库主键字段v_no有重复的时忽略错误
For i = 1 To 10000000
s = ""
For j = 1 To 16'生成随机16位数
Randomize
s = s & Mid("0123456789", Int(Rnd * 9) + 1, 1)
Next
Me.Caption = i & " " & s: DoEvents
conn.Execute "INSERT INTO verify(v_no) VALUES('" & s & "')"
Next
End Sub
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var obj = new GenDec16();
foreach (var item in obj)
{
Console.WriteLine(item);
}
}
}
class GenDec16 : IEnumerator, IEnumerator<string>, IEnumerable<string>
{
class Tree
{
public Tree(int Length)
{
node = new Node(0, Length);
}
Node node;
public string GenNewValue() { return node.GenNewValue(); }
public bool HasNewValue
{
get
{
return node.HasNewValue;
}
}
}
class Node
{
static Random rnd = new Random();
public Node(int id, int level)
{
ID = id;
Level = level;
HasNewValue = true;
if (level > 0) ChildNodes = new List<Node>();
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var obj = new GenDec16();
foreach (var item in obj)
{
Console.WriteLine(item);
}
}
}
class GenDec16 : IEnumerator, IEnumerator<string>, IEnumerable<string>
{
class Tree
{
public Tree(int Length)
{
node = new Node(0, Length);
}
Node node;
public string GenNewValue() { return node.GenNewValue(); }
public bool HasNewValue
{
get
{
return node.HasNewValue;
}
}
}
class Node
{
static Random rnd = new Random();
public Node(int id, int level)
{
ID = id;
Level = level;
HasNewValue = true;
if (level > 0) ChildNodes = new List<Node>();
}
Private Sub Command1_Click()
Dim D(99999999) As String, I As Long, Temp As String, J As Long
Randomize Timer
For I = 0 To UBound(D)
'前八位随机生成,后八位顺序产生,不管怎么说,肯定不重复
Temp = Format(10000000 * Rnd, "00000000") & Format(I, "00000000")
For J = 1 To 8
D(I) = D(I) & Mid(Temp, J, 1) & Mid(Temp, J + 8, 1) '把序号穿插在里边,只要序列号的位置固定
Next
Next
End Sub
--------------------编程问答--------------------
这样也好吧,至少接受起来比前边的好一些。
Private Sub Command1_Click()
Dim D(99999999) As String, I As Long, Temp As String, J As Long
Randomize Timer
For I = 0 To UBound(D)
'前八位随机生成,后八位顺序产生,不管怎么说,肯定不重复
Temp = Format(10000000 * Rnd, "00000000") & Format(I, "00000000")
For J = 1 To 8
D(I) = D(I) & Mid(Temp, J, 1) & Mid(Temp, J + 8, 1) '把序号穿插在里边,只要序列号的位置固定
Next
Next
End Sub
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var obj = new GenDec16();
foreach (var item in obj)
{
Console.WriteLine(item);
}
}
}
class GenDec16 : IEnumerator, IEnumerator<string>, IEnumerable<string>
{
class Tree
{
public Tree(int Length)
{
node = new Node(0, Length);
}
Node node;
public string GenNewValue() { return node.GenNewValue(); }
public bool HasNewValue
{
get
{
return node.HasNewValue;
}
}
}
class Node
{
static Random rnd = new Random();
public Node(int id, int level)
{
ID = id;
Level = level;
HasNewValue = true;
if (level > 0) ChildNodes = new List<Node>();
}
Private Sub Command1_Click()
Const TEXTBUFF As String = "0000000000000000"
Const ITEMSIZE As Long = 10000000
Const MULTIPLE As Long = 99999999 '用“8+8”
Dim strTextOut(ITEMSIZE - 1) As String
Dim strTemp$, i&
Randomize
For i = 0 To TEXTBUFF - 1
strTemp = TEXTBUFF
Mid$(strTemp, 1) = Int(Rnd() * MULTIPLE)
Mid$(strTemp, 9) = Int(Rnd() * MULTIPLE)
strTextOut(i) = strTemp
Next
End Sub
--------------------编程问答--------------------
CoCreateGuid
Creates a GUID, a unique 128-bit integer used for CLSIDs and inte易做图ce identifiers.
HRESULT CoCreateGuid(
GUID *pguid //Pointer to the GUID on return
);
Parameter
pguid
[out] Pointer to the requested GUID on return.
Return Value
S_OK
The GUID was successfully created.
Win32 errors are returned byUuidCreate but wrapped as an HRESULT.
Remarks
The CoCreateGuid function calls the RPC function UuidCreate, which creates a GUID, a globally unique 128-bit integer. Use the CoCreateGuid function when you need an absolutely unique number that you will use as a persistent identifier in a distributed environment.To a very high degree of certainty, this function returns a unique value – no other invocation, on the same or any other system (networked or not), should return the same value.
QuickInfo
Windows NT: Use version 3.1 or later.
Windows: Use Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in objbase.h.
Import Library: Included as a resource in ole32.dll.
See Also
UuidCreate
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int d[6];
int i,n,a,b,t;
int c,j;
void main() {
srand(time(NULL));
printf("shuffle 0..n-1 demo\n");
for (n=1;n<=5;n++) {/* 测试1~5个元素 */
printf("_____n=%d_____\n",n);
j=1;
for (c=1;c<=n;c++) j=j*c;/* j为n! */
j*=n*2;
for (c=1;c<=j;c++) {/* 测试n*2*n!次 */
for (i=0;i<n;i++) d[i]=i;/* 填写0~n-1 */
for (i=n;i>0;i--) {/* 打乱0~n-1 */
a=i-1;b=rand()%i;
if (a!=b) {t=d[a];d[a]=d[b];d[b]=t;}
}
printf("%04d:",c);
for (i=0;i<n;i++) printf("%d",d[i]);
printf("\n");
}
}
printf("shuffle 1..n demo\n");
for (n=1;n<=5;n++) {/* 测试1~5个元素 */
printf("_____n=%d_____\n",n);
j=1;
for (c=1;c<=n;c++) j=j*c;/* j为n! */
j*=n*2;
for (c=1;c<=j;c++) {/* 测试n*2*n!次 */
for (i=1;i<=n;i++) d[i]=i;/* 填写1~n */
for (i=n;i>1;i--) {/* 打乱1~n */
a=i;b=rand()%i+1;
if (a!=b) {t=d[a];d[a]=d[b];d[b]=t;}
}
printf("%04d:",c);
for (i=1;i<=n;i++) printf("%d",d[i]);
printf("\n");
}
}
}
Private Sub Command1_Click()
Const TEXTBUFF As String = "0000000000000000"
Const ITEMSIZE As Long = 10000000
Const VAL_BASE As Long = 12435
Const VAL_VOLA As Long = 99999 - VAL_BASE
Dim strTextOut(ITEMSIZE - 1) As String
Dim strTemp$, i&, iRnd&
Dim strDist$, p&
Randomize
For i = 0 To ITEMSIZE - 1
strTemp = TEXTBUFF
iRnd = VAL_BASE + Rnd() * VAL_VOLA
Mid$(strTemp, 11) = iRnd
iRnd = ULongCycL(i Xor iRnd, iRnd)
strDist = iRnd
p = 10 - Len(strDist)
Mid$(strTemp, p + 1) = iRnd
Mid$(strTemp, 16) = (p + Mid$(strTemp, 12, 1)) Mod 10
If (p > 0) Then Mid$(strTemp, 1) = Left$(Int(Rnd() * VAL_VOLA), p)
strTextOut(i) = strTemp
'If (CLng(jiemi(strTemp)) <> i) Then MsgBox "解密出错!", vbExclamation
Next
End Sub
Private Function ULongCycL(ByVal iValue As Long, ByVal iBitsN As Long) As Long
Dim iDivA&, iDivB&, iMASK&
If (iValue = 0) Then ULongCycL = 0: Exit Function
iBitsN = iBitsN Mod 31
If (iBitsN = 0) Then
ULongCycL = iValue: Exit Function
Else
iDivA = 2 ^ iBitsN
iDivB = 2 ^ (31 - iBitsN)
iMASK = iDivB - 1
ULongCycL = (iValue And iMASK) * iDivA _
Or (iValue And &H7FFFFFFF) \ iDivB
End If
End Function
Private Function ULongCycR(ByVal iValue As Long, ByVal iBitsN As Long) As Long
Dim iDivA&, iDivB&, iMASK&
If (iValue = 0) Then ULongCycR = 0: Exit Function
iBitsN = iBitsN Mod 31
If (iBitsN = 0) Then
ULongCycR = iValue: Exit Function
Else
iDivA = 2 ^ (31 - iBitsN)
iDivB = 2 ^ iBitsN
iMASK = iDivB - 1
ULongCycR = (iValue And iMASK) * iDivA _
Or (iValue And &H7FFFFFFF) \ iDivB
End If
End Function
Private Function jiemi(strEnText As String) As String
' 对生成的16位序列号“还原”原始序号
Dim p&, v&, strTemp$
p = (10 + (Mid$(strEnText, 16) - Mid$(strEnText, 12, 1))) Mod 10
v = Mid$(strEnText, 11, 5)
jiemi = ULongCycR(CLng(Mid$(strEnText, p + 1, 10 - p)), v) Xor v
End Function
Sub Main()
Const a As Long = 21 '乘法系数'
Const m As Long = 100000000 '模'
Const c As Long = 65519 '增量'
Dim r As Long '随机数'
Dim rLast As Long '前个随机数'
r = GetTickCount() '种子'
#If OUTPUT_MODE > 0 Then
Dim sCode As String
sCode = "00000000" & Format$(r, "00000000")
#End If
#If OUTPUT_MODE = 2 Then
Dim hFile As Integer
hFile = FreeFile()
Open App.Path & "\Code-16.csv" For Output Access Write As #hFile
#End If
Dim tc1 As Long
Dim tc2 As Long
Dim i As Long
tc1 = GetTickCount()
#If OUTPUT_MODE = 2 Then
For i = 0 To 1000000 '输出文件只测试100万个'
#ElseIf OUTPUT_MODE = 1 Then
For i = 0 To 10000000 '合成只测试1000万个'
#Else
For i = 0 To 100000000
#End If
rLast = r
r = (r * a + c) Mod m
#If OUTPUT_MODE > 0 Then
Mid$(sCode, 1, 8) = Mid$(sCode, 9, 8)
Mid$(sCode, 9, 8) = Format$(r, "00000000")
#End If
#If OUTPUT_MODE = 2 Then
'Print #hFile, Format$(rLast, "00000000"); Format$(r, "00000000")
Print #hFile, sCode
#End If
Next
tc2 = GetTickCount()
#If OUTPUT_MODE = 2 Then
Close #hFile
#End If
MsgBox (i - 1) & " 个用时 " & ((tc2 - tc1) / 1000) & " 秒。"
End Sub
Inter CPU 2.33GHz 的机器上,exe 执行结果
模式0: 1亿个用时 1.063 秒。
模式1: 1千万个用时 13.703 秒。
模式2: 1百万个用时 2.984 秒。——这个和硬盘有关,意义不大。
输出csv格式如下: