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

36
LINES

< > BotCompany Repo | #1035214 // WeightlessShuffledIteratorWithSeed (working backup with external LSFR)

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

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  
sclass WeightlessShuffledIteratorWithSeed<A> extends WeightlessShuffledIterator<A> {
7  
  final int cycleLength, offset;
8  
  
9  
  // initialize only with a length (and a pseudo-list)
10  
  // if you are going to be calling nextIndex() instead of next()
11  
  *(int n) {
12  
    this((L) virtualNullList(n));
13  
  }
14  
  
15  
  *(int n, int seed) {
16  
    this((L) virtualNullList(n), seed);
17  
  }
18  
  
19  
  *(L<A> list) {
20  
    this(list, 0);
21  
  }
22  
23  
  *(L<A> list, int seed) {
24  
    super(list);
25  
    if (lsfr == null) { cycleLength = offset = 0; ret; }
26  
    lsfr.start(seed);
27  
    cycleLength = lsfr.cycleLength();
28  
    offset = lsfr.value-1;
29  
    printVars ifdef WeightlessShuffledIterator_debug(+seed, +cycleLength, +offset, start := lsfr.value);
30  
  }
31  
  
32  
  int postProcessLSFRValue(int i) {
33  
    i += offset;
34  
    ret i >= cycleLength ? i-cycleLength : i;
35  
  }
36  
}

Author comment

Began life as a copy of #1035207

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035214
Snippet name: WeightlessShuffledIteratorWithSeed (working backup with external LSFR)
Eternal ID of this version: #1035214/1
Text MD5: 8b116a2d0e25f7ee3dc2b59831cc87e9
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-04-15 17:25:19
Source code size: 990 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 84 / 90
Referenced in: [show references]