# random

random

Author | Joep Suijs, Copyright © 2009, all rights reserved.
Adapted-by |
Compiler | >=2.4i

Description

    this library provides a (decent) random function.
    The formula is provided by *the* George Marsaglia.
    (see http://coding.derkeiler.com/Archive/C_CPP/comp.lang.c/2008-03/msg03691.html)

    /* initialize with any 32-bit seed x and any 32-bit y not 0 */
    static unsigned long x=2282008, y=362436069;
    #define sK ( x=69069*x+123, y^=y<<13, y^=y>>17, y^=y<<5, x+y )

    function random_byte returns an 8-bit random number
    function random_word returns a 16-bit random number
    functon dice         returns a number from 1 to 6

    Note: this library will recreate the same sequence. If this is undesired, assign a
          different (non-zero!) startup-value to _rndx and/or _rndy at startup.

    Note2: If you don't care about random quality and want to save a few processor cycles or
           memory bytes, define random_downgrade to select a basic random algorithm.

Sources

    Interface Copyright (C) 2005 Stef Mientki

Dependencies

No dependency found

## Summary

### Global variables/contants

- `var volatile dword _rndx = 2282008`
- `var byte nr`

### Procedures

### Functions

- `dice() return byte`
- `random_word() return word`
- `random_byte() return byte`

## API details

### Global variables/contants

- `var volatile dword _rndx = 2282008`

  No documentation found

- `var byte nr`

  No documentation found

### Procedures

### Functions

- `dice() return byte`

      dice - return a random number in the range [1..6]

- `random_word() return word`

      random_word - return a 16-bit random number

- `random_byte() return byte`

      random_byte - return an 8-bit random number

## Related samples

Here are the list of samples which use this library:

16f648a | 16f648a_random.jal
16f723 | 16f723_random.jal
16f73 | 16f73_random.jal
16f877 | 16f877_random.jal
16f877a | 16f877a_random.jal
16f88 | 16f88_random.jal
18f14k50 | 18f14k50_random.jal
18f2450 | 18f2450_random.jal
18f2520 | 18f2520_random.jal
18f2550 | 18f2550_random.jal
18f2620 | 18f2620_random.jal
18f452 | 18f452_random.jal
18f4550 | 18f4550_random.jal
18f4620 | 18f4620_random.jal
18f67j50 | 18f67j50_random.jal