Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

41
LINES

< > BotCompany Repo | #1035207 // WeightlessShuffledIteratorWithSeed

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (10297L/57K).

1  
// Allows to vary the order by supplying a seed
2  
//
3  
// We add the seed to every LSFR value generated, and also start
4  
// the LSFR with the seed.
5  
6  
// Not 100% sure if this works, there was an endless loop once
7  
8  
sclass WeightlessShuffledIteratorWithSeed<A> extends WeightlessShuffledIterator<A> {
9  
  final int offset;
10  
  
11  
  // initialize only with a length (and a pseudo-list)
12  
  // if you are going to be calling nextIndex() instead of next()
13  
  *(int n) {
14  
    this((L) iotaZeroList(n));
15  
  }
16  
  
17  
  *(int n, int seed) {
18  
    this((L) iotaZeroList(n), seed);
19  
  }
20  
  
21  
  *(L<A> list) {
22  
    this(list, 0);
23  
  }
24  
25  
  *(L<A> list, int seed) {
26  
    super(list);
27  
    if (n == 0) ret with offset = 0;
28  
    lsfr_start(seed);
29  
    offset = value-1;
30  
  }
31  
  
32  
  // copied from TripletLSFR.start
33  
  void lsfr_start(int seed) {
34  
    value = mod_31bit(seed, cycleLength)+1;
35  
  }
36  
  
37  
  int postProcessLSFRValue(int i) {
38  
    i += offset;
39  
    ret i >= cycleLength ? i-cycleLength : i;
40  
  }
41  
}

Author comment

Began life as a copy of #1035206

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035207
Snippet name: WeightlessShuffledIteratorWithSeed
Eternal ID of this version: #1035207/22
Text MD5: 75e1a03cd9a68794e5df4083cdd65fd1
Transpilation MD5: 060a0a397b6ae576669c992dea9956b7
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-02-12 14:45:18
Source code size: 988 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 140 / 314
Version history: 21 change(s)
Referenced in: [show references]