World Library  
Flag as Inappropriate
Email this Article

Full cycle

Article Id: WHEBN0002145989
Reproduction Date:

Title: Full cycle  
Author: World Heritage Encyclopedia
Language: English
Subject: Pseudorandom number generators, Linear congruential generator, Prime number
Publisher: World Heritage Encyclopedia

Full cycle

A full cycle or full period is a mathematical term that describes the behavior of a pseudorandom number generator (PRNG) over its set of valid states. In particular, a PRNG is said to have a full cycle if, for any valid seed state, the PRNG traverses every valid state before returning to the seed state, i.e. the period is equal to the cardinality of the state space.

The restrictions on the parameters of a PRNG for it to possess a full cycle are known only for certain types of PRNGs, such as, but not limited to, linear congruential generators and linear feedback shift registers. There is no general method to determine whether a PRNG algorithm is full-cycle short of exhausting the state space, which may be exponentially large compared to the size of the algorithm's internal state.

Example 1 (in C++)

Given a random number seed that is greater or equal to zero, a total sample size greater than 1, and an increment coprime to the total sample size, a full cycle can be generated with the following logic. Each nonnegative number smaller than the sample size occurs exactly once.

unsigned int seed = 0;
unsigned int sample_size = 3000;
unsigned int generated_number = seed % sample_size;
unsigned int increment = 7;
for(unsigned int iterator = 0; iterator < sample_size; ++iterator)
   generated_number = (generated_number + increment) % sample_size;

Example 1 (in Python)

# generator that goes through a full cycle
def cycle(seed, sample_size, increment):
    nb = seed
    for i in range(sample_size):
        nb = (nb + increment) % sample_size
        yield nb

# example values
seed = 17
sample_size = 100
increment = 13

# print all the numbers
print(list(cycle(seed, sample_size, increment)))

# verify that all numbers were generated correctly
assert set(cycle(seed, sample_size, increment)) == set(range(sample_size))

See also

This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.