Home > Software engineering >  The question of the random number seed
The question of the random number seed

Time:10-03

I had a program written in VB

But they also add the randomize

How can this timing boot, each and every day to get the first random number is the same


You give some ideas greatly, don't let the random Numbers are the same

CodePudding user response:

 Private Sub Form_Load () 
Randomize
Me. The Caption=CStr (Int (Rnd * 10000))
End Sub


Every time the start is not the same...

CodePudding user response:

reference 1st floor Topc008 response:
 Private Sub Form_Load () 
Randomize
Me. The Caption=CStr (Int (Rnd * 10000))
End Sub


Every time the start is not the same...

That, I mean if every time start the computer, and perform the procedure
Get the first random number is the same, I can't make the same
I understand what you said, is converted to a string to go, I try tomorrow, thank you

CodePudding user response:

Randomize without arguments are made of random seed system timer,
Can only say you boot time has been very stable, and the program is started the timer values are the same,
Try the following way, the seeds of the next day,
 Option Explicit 

Private Sub Form_Load ()
Randomize CLng (Now ())
Me. The Caption=CStr (Int (Rnd * 10000))
End Sub

CodePudding user response:

reference Tiger_Zhao reply: 3/f
Randomize without arguments are made of random seed system timer,
Can only say you boot time has been very stable, and the program is started the timer values are the same,
Try the following way, the seeds of the next day,
 Option Explicit 

Private Sub Form_Load ()
Randomize CLng (Now ())
Me. The Caption=CStr (Int (Rnd * 10000))
End Sub

This method is good, but like this, every time start for the random number as a

No satisfactory?

CodePudding user response:

You count the number of seconds a day in, just a change in the value of formula calculated,

CodePudding user response:

This specific to how to achieve
Can, for example, I'm a novice

CodePudding user response:

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

CodePudding user response:

The ultimate solution
 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" As Long As GUIDType (g)

Private Sub Command1_Click ()
Dim g As GUIDType
Call WinCoCreateGuid (g)
The Debug. Print g.D 1
Randomize g.D 1
The Debug. Print Rnd
End Sub

CodePudding user response:

CoCreateGuid
Creates a GUID, a unique 128 - bit integer, informs the for CLSIDs and interface identifiers.

HRESULT CoCreateGuid (
GUID * pguid//a Pointer to the GUID on return
);

The Parameter
Pguid
[out] Pointer to the requested GUID on the return.
The Return Value
S_OK
The GUID was successfully created.
Win32 errors are returned byUuidCreate but wrapped as an HRESULT.

Few
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.
The Import Library: Included as a resource in ole32. DLL.

See Also
UuidCreate




CodePudding user response:

Randomize the timer * 1000

CodePudding user response:

The range of timing boot, the timer is small,

CodePudding user response:

refer to the eighth floor zhao4zhong1 response:
ultimate solution
 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" As Long As GUIDType (g)

Private Sub Command1_Click ()
Dim g As GUIDType
Call WinCoCreateGuid (g)
The Debug. Print g.D 1
Randomize g.D 1
The Debug. Print Rnd
End Sub


From the top!
  • Related