Private Sub Form_Load() Randomize Me.Caption = CStr(Int(Rnd * 10000)) End Sub 这个每次启动都不一样啊....
Randomize 不带参数是用系统计时器做随机种子的。 只能说你开机时长一直很稳定,程序启动时取得的计时器值都是一样的。 用下面的方式试试,隔天的种子就不同了。 Option ExplicitPrivate Sub Form_Load() Randomize CLng(Now()) Me.Caption = CStr(Int(Rnd * 10000)) End Sub
Randomize CLng(CDbl(Now()-#2014-01-01#)*86400)
终极解决方案Private Type GUIDType D1 As Long D2 As Integer D3 As Integer D4(8) As Byte End Type Private Declare Function WinCoCreateGuid Lib "OLE32.DLL" Alias "CoCreateGuid" (g As GUIDType) As LongPrivate Sub Command1_Click() Dim g As GUIDType Call WinCoCreateGuid(g) Debug.Print g.D1 Randomize g.D1 Debug.Print Rnd End Sub
CoCreateGuid Creates a GUID, a unique 128-bit integer used for CLSIDs and interface 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.Res 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
Randomize
Me.Caption = CStr(Int(Rnd * 10000))
End Sub
这个每次启动都不一样啊....
只能说你开机时长一直很稳定,程序启动时取得的计时器值都是一样的。
用下面的方式试试,隔天的种子就不同了。
Option ExplicitPrivate Sub Form_Load()
Randomize CLng(Now())
Me.Caption = CStr(Int(Rnd * 10000))
End Sub
D1 As Long
D2 As Integer
D3 As Integer
D4(8) As Byte
End Type
Private Declare Function WinCoCreateGuid Lib "OLE32.DLL" Alias "CoCreateGuid" (g As GUIDType) As LongPrivate Sub Command1_Click()
Dim g As GUIDType
Call WinCoCreateGuid(g)
Debug.Print g.D1
Randomize g.D1
Debug.Print Rnd
End Sub
Creates a GUID, a unique 128-bit integer used for CLSIDs and interface 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.Res
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