Full cycle

Full cycle

A full cycle is a mathematical term that represents a traversal over a set of non-random numbers. A full cycle implies that every number in the set was chosen exactly once before repeating.

Full cycles are useful in Pseudorandom number generators.

Example 1 (in C++)

Given a random number seed that is greater or equal to zero.Given a total sample size greater than 1.Given a prime number that cannot be evenly divided into the total sample size.

A full cycle can be generated with the following logic. Each number in the sample_size should occur once.

unsigned int random_seed = 0;unsigned int sample_size = 3000;unsigned int generated_number = random_seed % sample_size;unsigned int prime_number = 7;unsigned int increment = prime_number;for(unsigned int iterator = 0; iterator < sample_size; ++iterator){ generated_number = (generated_number + increment) % sample_size;}

Example 2 (in C++)

// PseudoRandomTest1.cpp : Defines the entry point for the console application.
#include "stdafx.h"

int main(int argc, char* argv [] ){ unsigned int random_seed = 0; const unsigned int sample_size = 3000; unsigned int generated_number = random_seed % sample_size; unsigned int prime_number = 1; unsigned int increment = prime_number;

bool test [sample_size] = {0};

for(unsigned int iterator = 0; iterator < sample_size; ++iterator) { generated_number = (generated_number + increment) % sample_size; test [generated_number] = true;

static bool displayOnce = true; if (displayOnce) { printf("Predicable Random Numbers: "); displayOnce = false; }

printf("%d ", generated_number); }

for(unsigned int iterator = 0; iterator < sample_size; ++iterator) { if (!test [iterator] ) { static bool displayOnce = true; if (displayOnce) { printf(" You must have not used a prime number [ERROR] "); displayOnce = false; } printf("%d ", iterator); }

Example 2 (in C#)

using System;using System.Collections.Generic;using System.Text;

namespace PseudoRandomTest1{ class Program { static Boolean m_DisplayOnce = false;

static void Main(string [] args) { const UInt32 random_seed = 0; const UInt32 sample_size = 3000; UInt32 generated_number = random_seed % sample_size; const UInt32 prime_number = 751; const UInt32 increment = prime_number; Boolean [] test = new Boolean [sample_size] ; m_DisplayOnce = true; for(UInt32 iterator = 0; iterator < sample_size; ++iterator) { generated_number = (generated_number + increment) % sample_size; test [generated_number] = true;

if (m_DisplayOnce) { Console.WriteLine("Predicable Random Numbers:"); m_DisplayOnce = false; }

Console.Write("{0} ", generated_number); } m_DisplayOnce = true; for(UInt32 iterator = 0; iterator < sample_size; ++iterator) { if (!test [iterator] ) { if (m_DisplayOnce) { Console.WriteLine(); Console.WriteLine("You must have not used a prime number [ERROR] "); m_DisplayOnce = false; } Console.Write("{0} ", iterator); } } }

ee also

* Linear congruential generator
* Prime numbers
* [http://primes.utm.edu/lists/small/millions/ Lists of Prime Numbers]


Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • Full Cycle Recordings — is a record label based in Bristol, England specialising in drum and bass. The label is a sister label of V Recordings and is owned and run by Daniel Kausman (DJ Die), Paul Southey (DJ Suv), Keith Thompson (DJ Krust) and Ryan Williams (Roni Size) …   Wikipedia

  • cycle — n. 1) to complete a cycle; to come full cycle 2) to go through, pass through a cycle 3) a business; economic; estrous (AE), oestrous (BE); life; menstrual cycle 4) (as on a washing machine) a delicate; normal; permanent press cycle 5) in cycles… …   Combinatory dictionary

  • Cycle of the Werewolf —   First edition cover …   Wikipedia

  • Cycle — Cy cle (s? k l), n. [F. ycle, LL. cyclus, fr. Gr. ky klos ring or circle, cycle; akin to Skr. cakra wheel, circle. See {Wheel}.] 1. An imaginary circle or orbit in the heavens; one of the celestial spheres. Milton. [1913 Webster] 2. An interval… …   The Collaborative International Dictionary of English

  • Cycle of eclipses — Cycle Cy cle (s? k l), n. [F. ycle, LL. cyclus, fr. Gr. ky klos ring or circle, cycle; akin to Skr. cakra wheel, circle. See {Wheel}.] 1. An imaginary circle or orbit in the heavens; one of the celestial spheres. Milton. [1913 Webster] 2. An… …   The Collaborative International Dictionary of English

  • Cycle of indiction — Cycle Cy cle (s? k l), n. [F. ycle, LL. cyclus, fr. Gr. ky klos ring or circle, cycle; akin to Skr. cakra wheel, circle. See {Wheel}.] 1. An imaginary circle or orbit in the heavens; one of the celestial spheres. Milton. [1913 Webster] 2. An… …   The Collaborative International Dictionary of English

  • Cycle of the moon — Cycle Cy cle (s? k l), n. [F. ycle, LL. cyclus, fr. Gr. ky klos ring or circle, cycle; akin to Skr. cakra wheel, circle. See {Wheel}.] 1. An imaginary circle or orbit in the heavens; one of the celestial spheres. Milton. [1913 Webster] 2. An… …   The Collaborative International Dictionary of English

  • Cycle of the sun — Cycle Cy cle (s? k l), n. [F. ycle, LL. cyclus, fr. Gr. ky klos ring or circle, cycle; akin to Skr. cakra wheel, circle. See {Wheel}.] 1. An imaginary circle or orbit in the heavens; one of the celestial spheres. Milton. [1913 Webster] 2. An… …   The Collaborative International Dictionary of English

  • cycle of the Sunday letter — Cycle Cy cle (s? k l), n. [F. ycle, LL. cyclus, fr. Gr. ky klos ring or circle, cycle; akin to Skr. cakra wheel, circle. See {Wheel}.] 1. An imaginary circle or orbit in the heavens; one of the celestial spheres. Milton. [1913 Webster] 2. An… …   The Collaborative International Dictionary of English

  • Cycle speedway — is a form of bicycle racing on short oval dirt tracks, usually outdoors, occasionally indoors, typically 70 90 metres long. Like motorcycle speedway, riders use machines without brakes or multiple gears but, unlike motor speedway, the object is… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”