Specific embodiment
Pseudo-random algorithm generates random number using recurrence formula, and according to the difference of specific algorithm, recurrence formula be can be
Single order, it is also possible to second order or multistage.By taking second order as an example, recurrence formula is as shown in Equation 1:
xn+2=f (xn+1, xn), the formula of n >=01
In formula 1, xn、xn+1、xn+2For random factor.To second order recursive algorithm, x0And x1For initial value.
Random number sequence generated is as shown in Equation 2:
rk=g (xk), the formula of k >=22
It, can be by random factor directly as random number (r at this time generated according to the demand of concrete application scenek=
xk);Corresponding random number is obtained after can also converting to random factor doing mathematics.
And not all recursive algorithm may serve to generate random number, only be passed through with the sequence that recursive algorithm generates
It crosses check character and unifies a little statistics requirements, such as uniformity, the randomness of sampling are met certain condition, such recursive algorithm is
It can be used as pseudo-random algorithm.That is, pseudo-random algorithm is started with some initial value, recursion generates a system several times
Column random factor, these random factors do not have duplicate happen substantially.
In this way, when to generate L random number on first node in cluster, it is meant that recursion on this node will be into
Row L times, if second node, using resulting random factor after the node recursion at least L times as initial value, second is saved
The initial value of point substantially will not be identical with the initial value of first node.This mode is generalized to and is used to generate at random in cluster
Several all nodes, then the initial value of each node substantially will not be identical with the initial value of other nodes.
Based on above-mentioned thinking, embodiments herein proposes a kind of generation method of new pseudo random number, in the cluster may be used
Initial value is saved for the predetermined storage location of each node visit, reads initial value from the predetermined storage location in each node
Afterwards, carrying out obtaining after recursive operation this node several times will not continue to random factor for recursive operation, as initial
Value write-in predetermined storage location, for other nodes use, thus can ensure substantially each node initial value and other
Node is different, to solve problems of the prior art.
Cluster in the embodiment of the present application includes at least two nodes, and each node is that an operation pseudo-random algorithm generates
The unit of random number, for example, node can be a physical server, a logical device (such as virtual machine or simulator) or
One independently operated program example of person etc..To the method for operation of cluster and networking structure, node in embodiments herein
Type and communication mode etc. without limitation.
In the embodiment of the present application, the process of the generation method of the pseudo random number run on each node is as shown in Figure 1.
Step 110, starting random factor is obtained from predetermined storage location.
In embodiments herein, predetermined storage location can be run all node visits of pseudo-random algorithm in cluster,
And these nodes all have the permission of read-write to the content for being stored in predetermined storage location.Predetermined storage location, which can be, to be collected
It, can also be in the equipment outside cluster, without limitation on some node in group.For example,
Starting random factor is used by the nodes to input recurrence formula as initial value to generate random number sequence.In cluster
The pseudo-random algorithm of identical order is run on each node, the initial value number of the pseudo-random algorithm of different rank is different.Starting
The order of pseudo-random algorithm run in the number of random factor and node is identical, the number for the value that predetermined storage location is saved
It is identical as the starting number of random factor of each node.When the number for starting random factor is more than one, each node is pressed
Each starting random factor is assigned according to the value that same sequence saves predetermined storage location.
Step 120, the number upper limit of random number to be generated according to starting random factor and this node, determine stop it is random because
Son, and random factor will be stopped, the predetermined storage location is written.
Assuming that the number upper limit that this node will generate random number is N (N is natural number), opened from predetermined storage location reading
After dynamic random factor, node carries out at least K times with the recurrence formula in pseudo-random algorithm and passs to start random factor as initial value
Push away (K be not less than N), if the order m (m is natural number) of the used pseudo-random algorithm of node, the k-th that recursion is obtained it is random because
Son is to (K-m-1) a random factor as suspension random factor.Node will stop random factor and predetermined storage location is written, will
The original value of predetermined storage location is updated to stop random factor.When stop random factor be more than one when, each node according to
With sequence same when reading starting random factor from predetermined storage location, random factor will be stopped, predetermined storage location is written.
For example, starting random factor to the pseudo-random algorithm using single order recursive algorithm and stopping random factor and all only have
One, node runs n times pseudo-random algorithm, obtains n-th random factor to start random factor as initial value.Due to this
The number upper limit that node will generate random number is N, this node will not be a random come recursion (N+1) with n-th random factor again
The factor, therefore this node can be written to predetermined storage location, for other using n-th random factor as random factor is stopped
Node is used as starting random factor.
In application scenes, entire cluster, which needs to generate using some pseudo-random algorithm, is no more than some quantification
Random number, at this time can be using the random number of this quantification as the number upper limit that generate random number on each node.
If the entire cluster random number quantity to be generated is difficult to determine, the number upper limit for the random number to be generated on each node
Also it being difficult to determine, each node can be enabled at this time and generate random number according to batch, every batch of generates a certain number of random numbers,
When the random number that a batch generates reaches the quantity, node reacquires initial value from predetermined storage location.Specifically,
In the starting of every batch of, node obtains starting random factor from predetermined storage location, and this batch volume residual is set to this batch
The secondary number upper limit;Node to start random factor as initial value, when needing to generate random number every time i.e. the primary puppet of operation with
Machine algorithm obtains next random factor, and subtracts one for this batch volume residual, until this batch volume residual is zero;When this batch
When secondary volume residual is zero, node starts next batch, obtains starting random factor from predetermined storage location and with this batch
The number upper limit resets this batch volume residual.
It should be noted that this batch number upper limit of each batch of node may be the same or different.This batch
The number upper limit can be determined according to cluster operation conditions by cluster controller by the preparatory manual setting of administrator and be notified to save
Point can also be automatically generated by node according to self-operating situation, and embodiments herein is without limitation.When each batch of node
This batch number upper limit when may be different, node can obtain the sheet of next batch when this batch volume residual is zero
Batch number upper limit value.
Starting random factor is being read from a node by predetermined storage location, is being updated to stop to by predetermined storage location
Random factor during the visit in, may there are other nodes to wish to obtain initial value from predetermined storage location.In order to avoid at this time
Other nodes obtain identical initial value, and node can be deposited before obtaining starting random factor from predetermined storage location to predetermined
Storage space sets locking;And after it will stop random factor write-in predetermined storage location, predetermined storage location is unlocked.In this way, other
Node only after the node updates the value of predetermined storage location, can just read initial value.
It should be noted that the realization of predetermined storage location is different in different concrete application scenes, if pre- in scene
Locking and unlocking function has been provided in the access mechanism itself for determining storage location, such as predetermined storage location is that each node can
Certain record in the database of access, then no longer need that predetermined storage location is separately locked and unlocked.
Step 130, it to start random factor as initial value, is generated according to pseudo-random algorithm and is no more than the number upper limit
Random number.
After obtaining starting random factor, when needing to generate random number, in the number that this node will generate random number
In limit, node runs pseudo-random algorithm, and gradually recursion generates random number sequence.
In the realization that each node generates random number according to batch, this batch of this node in random number to be generated
In the number upper limit, operation pseudo-random algorithm generates random number sequence.
As it can be seen that saving operation in the cluster in embodiments herein for the predetermined storage location of each node visit
The initial value of pseudo-random algorithm, the value of preservation is updated to unduplicated value after obtaining initial value by each node, for it
He uses node as initial value.Each node is enabled in this way and generates random number using different initial values, greatly
Reduce a possibility that different nodes generate same random number, avoid caused by being repeated because of initial value under the cluster speed of service
Drop, and cluster can be shortened to the response time of user.
In addition, if the pseudo-random algorithm run on each node in cluster is different, or the identical pseudorandom of operation is calculated
Method but the used parameter difference in addition to initial value, for all random numbers that entire cluster generates, the statistical properties
The random number sequence often generated not as good as recursion on a node.And in embodiments herein, when each node in cluster
It is upper to run identical pseudo-random algorithm, and in addition to initial value, the other parameters of the pseudo-random algorithm of each node operation are identical
When, the random number that each node generates in entire cluster is equivalent to the random number sequence generated on a node, can reach good
Good statistics index improves the quality of the random number of cluster generation.
In the application example of the application, cluster includes multiple nodes, and each node is a jvm (Java
Virtual Machine, Java Virtual Machine) example.The cluster is used to receive the request of user, is used as sound after generating random password
User should be replied to.Each jvm example generates random number sequence by linear congruent algorithm, and in addition to initial value, often
Other parameters used by linear congruent algorithm are identical in a jvm example.
Predetermined position in all addressable databases of jvm example in the cluster, it is random to preserve linear congruent algorithm
The initial value of the factor.The table for being used for storing initial value is established in the database, and a kind of possible structure is as shown in table 1:
ID |
Gmt_create |
Gmt_modified |
Seed |
1 |
2015/4/4 |
2015/4/4 |
0 |
Table 1
In table 1, ID is line identifier;Gmt_create is the time of origin for creating the record;Gmt_modified is the note
The time of origin of the last modification of record;Seed is the initial value of the random factor currently saved.
Each jvm example generates random number according to batch, and every batch of number of run constant is preset in each jvm example
The number upper limit for the random number that T namely every batch of produce.
When starting operation, the value of remaining number of run variable is 0 in each jvm example.Receive every time user with
When machine password request, the operational process in each jvm example is as shown in Figure 2.
Step 201, the random password request of user is received.
Step 202, whether the remaining number of run for judging this batch is zero, if so, executing step 203;If not, turning
Step 207;
Step 203, starting random factor is read from the predetermined position in database.In jvm example access database
When the record, database locks the record.
Step 204, using starting random factor as initial value, T sublinear congruence algorithm is executed, the T that recursion is gone out
Random factor is as suspension random factor.
Step 205, the predetermined position in random factor write-in database will be stopped, updates the record.It will remember in jvm example
After record updates, data unlock the record.
Step 206, a upper random factor variable is set to starting random factor, this batch residue number of run is set to
T。
Step 207, this random factor is obtained by a upper random factor recursion, a upper random factor variable is set to
This random factor, and remaining number of run is subtracted one.
Step 208, resulting random factor is run according to this and generates random password, returned as to the response that user requests
Back to user.
Corresponding with the realization of above-mentioned process, embodiments herein additionally provides a kind of pseudorandom applied on clustered node
Several generating means.The device can also be realized by software realization by way of hardware or software and hardware combining.With
It is CPU (the Central Process of equipment where clustered node as the device on logical meaning for software realization
Unit, central processing unit) by corresponding computer program instructions be read into memory operation formed.For hardware view,
Other than CPU shown in Fig. 3, memory and nonvolatile memory, the equipment where the generating means of pseudo random number is usual
It further include for realizing other hardware such as board of network communicating function.
Fig. 4 show a kind of generating means of pseudo random number provided by the embodiments of the present application, using node in the cluster
On, described device includes initial value acquiring unit, initial-value generating unit and random number generation unit, in which: initial value obtains
Unit is used to obtain starting random factor from predetermined storage location;Initial-value generating unit is used for according to starting random factor and this
Node will generate the number upper limit of random number, determine and stop random factor, and will stop random factor and the predetermined storage is written
Position;Random number generation unit is used to be generated according to pseudo-random algorithm described in being no more than to start random factor as initial value
The random number of the number upper limit.
Optionally, the initial-value generating unit is specifically used for: to start random factor as initial value, running n times institute
Pseudo-random algorithm is stated, using obtained n-th random factor as suspension random factor, and it is described pre- to stop random factor write-in
Determine storage location;N is the number upper limit that this node will generate random number.
Optionally, the number upper limit is this batch number upper limit of this batch of this section point random number to be generated;It is described
Device further includes volume residual reset cell and volume residual updating unit, in which: volume residual reset cell is used for from pre-
After determining storage location acquisition starting random factor, this batch volume residual is set to this batch number upper limit;Volume residual updates
Unit is used for after generating each random number, subtracts one for this batch volume residual, until this batch volume residual is zero;It is described
Initial value acquiring unit is specifically used for: when this batch volume residual is zero, from predetermined storage location obtain this batch starting with
The machine factor.
Optionally, described device further includes locking unit and unlocking unit, in which: locks unit and is used for from predetermined storage
Before position acquisition starts random factor, predetermined storage location is locked;Unlocking unit is used to that random factor write-in will to be stopped in advance
After determining storage location, predetermined storage location is unlocked.
Optionally, identical pseudo-random algorithm is run on each node in the cluster;In addition to initial value, it is described it is pseudo- with
The other parameters that machine algorithm uses are identical.
The foregoing is merely the preferred embodiments of the application, not to limit the application, all essences in the application
Within mind and principle, any modification, equivalent substitution, improvement and etc. done be should be included within the scope of the application protection.
In a typical configuration, calculating equipment includes one or more processors (CPU), input/output interface, net
Network interface and memory.
Memory may include the non-volatile memory in computer-readable medium, random access memory (RAM) and/or
The forms such as Nonvolatile memory, such as read-only memory (ROM) or flash memory (flash RAM).Memory is computer-readable medium
Example.
Computer-readable medium includes permanent and non-permanent, removable and non-removable media can be by any method
Or technology come realize information store.Information can be computer readable instructions, data structure, the module of program or other data.
The example of the storage medium of computer includes, but are not limited to phase change memory (PRAM), static random access memory (SRAM), moves
State random access memory (DRAM), other kinds of random access memory (RAM), read-only memory (ROM), electric erasable
Programmable read only memory (EEPROM), flash memory or other memory techniques, read-only disc read only memory (CD-ROM) (CD-ROM),
Digital versatile disc (DVD) or other optical storage, magnetic cassettes, tape magnetic disk storage or other magnetic storage devices
Or any other non-transmission medium, can be used for storage can be accessed by a computing device information.As defined in this article, it calculates
Machine readable medium does not include temporary computer readable media (transitory media), such as the data-signal and carrier wave of modulation.
It should also be noted that, the terms "include", "comprise" or its any other variant are intended to nonexcludability
It include so that the process, method, commodity or the equipment that include a series of elements not only include those elements, but also to wrap
Include other elements that are not explicitly listed, or further include for this process, method, commodity or equipment intrinsic want
Element.In the absence of more restrictions, the element limited by sentence "including a ...", it is not excluded that including described want
There is also other identical elements in the process, method of element, commodity or equipment.
It will be understood by those skilled in the art that embodiments herein can provide as method, system or computer program product.
Therefore, complete hardware embodiment, complete software embodiment or embodiment combining software and hardware aspects can be used in the application
Form.It is deposited moreover, the application can be used to can be used in the computer that one or more wherein includes computer usable program code
The shape for the computer program product implemented on storage media (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.)
Formula.