Difference between revisions of "RANDOMIZE"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 11: Line 11:
* The fact that random numbers would always be the same has been used for simple data encrytion.
* The fact that random numbers would always be the same has been used for simple data encrytion.
* Using a [[TIMER]] starting value ensures that the initial return sequence values are different almost every time!
* Using a [[TIMER]] starting value ensures that the initial return sequence values are different almost every time!
* [[RUN]] should reset the RANDOMIZE sequence to the starting value.





Revision as of 20:09, 1 February 2012

RANDOMIZE is used with a seed value to generate different random number sequences using the RND function.


Syntax

RANDOMIZE [USING] seednumber


  • The seednumber can be any positive or negative numerical value. The TIMER value is often used to change RND output each run.
  • USING resets a seed number sequence to the start of the sequence as if the program just started using that seed.
  • If the same initial seed number is used, the sequence of random numbers returned will be identical every program run.
  • The fact that random numbers would always be the same has been used for simple data encrytion.
  • Using a TIMER starting value ensures that the initial return sequence values are different almost every time!
  • RUN should reset the RANDOMIZE sequence to the starting value.


Example: Using RANDOMIZE TIMER to set a different starting sequence of numbers every run.

RANDOMIZE TIMER DO randnum% = INT(RND * 11) + 2 'add one to multiplier as INT rounds down and never equals 10 PRINT randnum% K$ = INPUT$(1) LOOP UNTIL UCASE$(K$) = "Q" 'q = quit END

Explanation: Procedure generates random integer values from 2 to 12 like a pair of dice.


See also:



Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page