我用VB写了个程序里头也加了 randomize可如何每天定时开机,程序得到第一个随机数都是相同的
各位大大给点思路,不让随机数相同

解决方案 »

  1.   

    Private Sub Form_Load()
        Randomize
        Me.Caption = CStr(Int(Rnd * 10000))
    End Sub
    这个每次启动都不一样啊....
      

  2.   

    Randomize 不带参数是用系统计时器做随机种子的。
    只能说你开机时长一直很稳定,程序启动时取得的计时器值都是一样的。
    用下面的方式试试,隔天的种子就不同了。
    Option ExplicitPrivate Sub Form_Load()
        Randomize CLng(Now())
        Me.Caption = CStr(Int(Rnd * 10000))
    End Sub
      

  3.   

    Randomize CLng(CDbl(Now()-#2014-01-01#)*86400)
      

  4.   

    终极解决方案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
      

  5.   

    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  
      

  6.   

    Randomize timer*1000 就行了
      

  7.   

    定时开机,timer 的范围就小了。