CL_ABAP_RANDOM - Pseudo Random Number Generator

ABAP Short Reference   PERFORM Short Reference  
This documentation is copyright by SAP AG.

Functionality

This class implements the basic version of a pseudo-random number generator. It is based on the MersenneTwister algorithm. This algorithm guarantees a high period length for the generated values, and ensures that values are evenly distributed when multi-dimensional data is generated.

The class CL_ABAP_RANDOM can return pseudo-random integers for whole numbers, floating-point numbers,or packed numbers for simple applications. It should only be used if you absolutely have to generatemulti-dimensional data with components of different types. To generate one-dimensional values with a specific type, you should use the set of classes specified at the end of this document.

The Mersenne Twister is incorporated in the ABAP runtime environment as an Open Source product. For this reason, we have to include the following text in this document:

/*
   A C-program for MT19937, with initialization improved 2002/2/10.
   Coded by Takuji Nishimura and Makoto Matsumoto.
   This is a faster version by taking Shawn Cokus's optimization,
   Matthe Bellew's simplification, Isaku Wada's real version.

   Before using, initialize the state by using init_genrand(seed)
   or init_by_array(init_key, key_length).

   Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
   All rights reserved.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:

     1. Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.

     2. Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in
        documentation and/or other materials provided with the distribution

     3. The names of its contributors may not be used to endorse or promote
        products derived from this software without specific prior
        written permission.

THIS SOFTWAREIS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTEGOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANYTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

   Any feedback is very welcome.
   http://www.math.keio.ac.jp/matumoto/emt.html
   email: matumoto@math.keio.ac.jp
*/

Relationships

CL_ABAP_RANDOM is a final class.

Example

REPORT random_numbers.

DATA prng TYPE REF TO CL_ABAP_RANDOM.
DATA num  TYPE I.

START-OF-SELECTION.
  prng = CL_ABAP_RANDOM=>create( ).
  DO 10000 TIMES.
    num = prng->Int( ).
    WRITE / num.
  ENDDO.

Notes

This pseudo-random number generator is not suitable for use in cryptography applications.

This sequence of numbers is calculated exclusively on the basis of integer operations. The sequence that is calculated from a fixed starting number is always identical (reproducibility). This is platform- neutral.

Further information

For more information on the Mersenne Twister:

http://www.math.keio.ac.jp/matumoto/emt.html

Other classes used to generate pseudo-random numbers:

CL_ABAP_RANDOM_FLOAT
CL_ABAP_RANDOM_INT
CL_ABAP_RANDOM_PACKED
CL_ABAP_RANDOM_PACKED_DEC1
CL_ABAP_RANDOM_PACKED_DEC2
CL_ABAP_RANDOM_PACKED_DEC3
CL_ABAP_RANDOM_PACKED_DEC4
CL_ABAP_RANDOM_PACKED_DEC5
CL_ABAP_RANDOM_PACKED_DEC6
CL_ABAP_RANDOM_PACKED_DEC7
CL_ABAP_RANDOM_PACKED_DEC8
CL_ABAP_RANDOM_PACKED_DEC9
CL_ABAP_RANDOM_PACKED_DEC10
CL_ABAP_RANDOM_PACKED_DEC11
CL_ABAP_RANDOM_PACKED_DEC12
CL_ABAP_RANDOM_PACKED_DEC13
CL_ABAP_RANDOM_PACKED_DEC14######################################################################################################################################################################################


rdisp/max_wprun_time - Maximum work process run time   BAL_S_LOG - Application Log: Log header data  
This documentation is copyright by SAP AG.


Length: 5485 Date: 20120526 Time: 082506     triton ( 194 ms )