Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9136457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:57:19+00:00 2026-06-17T08:57:19+00:00

Question spawned from this one . The problem can be formulated as follows: Given

  • 0

Question spawned from this one. The problem can be formulated as follows:

Given two positive integers n and m, with m <= n, is there a way to find a suite of numbers, which cycles and covers all possible values from 0 to n?

As a basic example, if we take 3 as a number, for whatever number current between 0 and 3, we can compute the next value as:

next = (current+3) % 4

This will cycle. For instance: 1 -> 0 -> 3 -> 2 -> 1 etc. I found this solution by “chance” and it is even general ((i + n) % (n + 1) for any n), I cannot prove it mathematically. And it is a little too obvious.

Are there better ways to generate such a permutation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:57:19+00:00Added an answer on June 17, 2026 at 8:57 am

    I’m not sure what you intend m in the question to refer to, or how you’re defining “a suite of numbers”). However, one way of getting a cycle of number is to use a recursion (or iteration) of the form:

    next = f(current)
    

    for some function f. For example, linear congruential RNGs use the iteration:

    x = ( a · x + c ) mod m   where 0 < a, c < m
    

    They don’t always produce all values from 0 to m-1, but under certain circumstances they do:

    c and m are relatively prime
    
    a - 1 is divisible by every prime factor of m (not including m)
    
    if m is divisible by 4, a - 1 is divisible by 4.
    

    (This is the Hull-Dobell theorem.)

    Note that a, c == 1 satisfies the above criteria for any m. Futhermore, if m is prime, any values of a and c satisify the criteria, and if m is a power of 2, then the criteria are satisfied by any a, c such that a == 1 mod 4 and c == 1 mod 2. However, for certain values of m (eg. 6), the only value of a which will work is 1.

    This might not qualify as “stateless”, but I don’t think that there is any strictly stateless solution; for example, you might look for some function f such that:

    f(0), f(1),... f(m-1)
    

    is a permutation of

    0, 1, ..., m-1
    

    so that you could generate the cycle by calling f(i) for successive values of i. But that’s still a state, since you have to remember the last value of i you used,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is spawned from the partial answer to JSF2: why does empty test
Note: This question was spawned from another question I had regarding the use of
This question has spawned out of this one. Working with lists of structs in
I thought I'd get this question out there while I noodled on a solution
First, here's my original question that spawned all of this . I'm using Appcelerator
Spawned by this question: Bitwise AND in Sql Server In response to the above
This one's really kicking my backside. I have a form, spawned and owned by
Question context: let say that there is some really important row in config/locales/en.yml that
Question from Object-Oriented JavaScript book: Imagine Array() doesn't exist and the array literal notation
My guesses were wrong, and had nothing to do with the answer. This question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.