Creating a non-repeating set from a random seed and getting the result by index

ps I called it like Random, but this is a random seed-based random case where the seed will be generated by PRNG, but with the same seed the same “random” distribution will be observed.

I'm currently trying to find a way to help do 2 things:

1) Non-repeating sequence generation

This will require 2 arguments Seed; and N. It will generate a sequence of size Nfilled with numbers between 1and Nwithout repetition.

I have found some good methods for this, but most of them come up with feasibility in the second part.

2) Extract a record from a sequence

It takes 3 arguments Seed; N; and I. This is to determine which value will be displayed in the position Iin the sequence to be generated with Seedand N. However, in order to work with what I mean, he absolutely cannot use the generated sequence and select the element.

At first I worked with preliminary calculation of the sequence, then I requested it, but it really only works in test cases, since the number Seedsand value Nthat will be used will create the database in Petabytes.

From what I can say, a method that implements requirement 1 using requirement 2 would be the most ideal method.

i.e. the sequence is generated:

function Generate_Sequence(int S, int N) {
    int[] sequence = new int[N];
    for (int i = 0; i < N; i++) {
        sequence[i] = Extract_From_Sequence(S, N, i);
    }
    return sequence;
}

Example

GS = Generate Sequence
ES = Extract from Sequence

for:
 S = 1
 N = 5
 I = 4

GS(S, N) = { 4, 2, 5, 1, 3 }
ES(S, N, I) = 1

let S = 2

GS(S, N) = { 3, 5, 2, 4, 1 }
ES(S, N, I) = 4
+4
1

- . , N ( !). S \sigma {1,2,..., log (n)}. \sigma, '. , ' \sigma (x) x. ( XOR). , p gcd (p, N) = 1 ( Ns) (q < N) S. Extract_From_Sequence (S, N, I) (p * '+ q mod N).

, N . , ' [1, N]. , . \sigma (log (n)) ' log (n) .....

+1

Source: https://habr.com/ru/post/1627651/


All Articles