我用VB寫了個程式
里頭也加了 randomize
可如何每天定時開機,程式得到第一個亂數都是相同的
各位大大給點思路,不讓亂數相同
uj5u.com熱心網友回復:
Private Sub Form_Load()
Randomize
Me.Caption = CStr(Int(Rnd * 10000))
End Sub
這個每次啟動都不一樣啊....
uj5u.com熱心網友回復:
那個,我說的是如果每天定時啟動電腦,并執行程式
獲得第一個亂數字都一樣,我想不讓其一樣
你說的我看明白,難道轉成字串就行了,我明天試試,謝謝
uj5u.com熱心網友回復:
Randomize 不帶引數是用系統計時器做隨機種子的。只能說你開機時長一直很穩定,程式啟動時取得的計時器值都是一樣的。
用下面的方式試試,隔天的種子就不同了。
Option Explicit
Private Sub Form_Load()
Randomize CLng(Now())
Me.Caption = CStr(Int(Rnd * 10000))
End Sub
uj5u.com熱心網友回復:
這個方法不錯,不過這樣寫,每次啟動獲得的亂數就一樣了
沒有兩全的嗎?
uj5u.com熱心網友回復:
那么你把一天之中的秒數也算上,只要公式算出來的值有變化就行。uj5u.com熱心網友回復:
這個具體要怎么實作呢能舉個例子嗎,俺是新手
uj5u.com熱心網友回復:
Randomize CLng(CDbl(Now()-#2014-01-01#)*86400)
uj5u.com熱心網友回復:
終極解決方案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 Long
Private Sub Command1_Click()
Dim g As GUIDType
Call WinCoCreateGuid(g)
Debug.Print g.D1
Randomize g.D1
Debug.Print Rnd
End Sub
uj5u.com熱心網友回復:
CoCreateGuidCreates 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.
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
uj5u.com熱心網友回復:
Randomize timer*1000 就行了uj5u.com熱心網友回復:
定時開機,timer 的范圍就小了。uj5u.com熱心網友回復:
自頂!
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/108051.html
標籤:網絡編程
