|
|
|
Web site http://Programming - generating random numbers.
Description
All events that happens to us, there are two types - natural and accidental. For example, you communicate with friends and discussed the trip
Statistics summary
[Rank]
[Visitors]
|
select category: Computers & Internet |
||||||||||||||||||||||||||
|
Advanced site description
Basic operation of the issuance of random values
All events that happens to us, there are two types - natural and accidental. For example, you communicate with friends and discussed the trip to the country - have fun, ie an example of a natural and expected event. But, immediately after the call began to rain, which randomly ruined all your plans. Jobs random number generator is entirely dependent on an embedded feature in the mechanism, then all the numbers that are issued in this event are pseudo-random. The functions that generate random numbers, apply at the time - the system. Who would that not telling, but nothing is random and logical, and programming - even more so.
Operator rand
To get a random value, a random number generator uses specialized functions for the issuance of the required values. And so, to create a random value using the function rand, rand function is used to produce random values that can have a range from zero, and to set constants. The required constant is specified in a preprocessor file, there is our function rand. This function is simple to use: type of variable c = rand (); finite value set: rand% number. When you start the application, always, random values will be identical. A miss is that the rand operator controlled by the same system time, which is preserved during compilation. All this random generator operates on the mechanism of change in the software timer, then all will go to hell.
About srand and random
Function srand is an indispensable way to problems when the program code apply to the operator rand, srand resets the system timer. Application of the current function srand rand operator opened up the possibility to apply to the current built-in timer, and not to record when compiling, so the operation of the generator is carried out correctly. Recently programming in C + + has learned to vary from microseconds, allowing the algorithm to improve the issuance of random values. Innovation was formed in the function random, which also increased the range of valid numbers.
|
|||||||||||||||||||||||||||
|
|
Copyright © 2008 Free Url Dir, Inc. All rights reserved.
Developed by Vitalina Web Technologies
|
|