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).

// Allows to vary the order by supplying a seed
//
// We add the seed to every LSFR value generated, and also start
// the LSFR with the seed.

// Not 100% sure if this works, there was an endless loop once

sclass WeightlessShuffledIteratorWithSeed<A> extends WeightlessShuffledIterator<A> {
  final int offset;
  
  // initialize only with a length (and a pseudo-list)
  // if you are going to be calling nextIndex() instead of next()
  *(int n) {
    this((L) iotaZeroList(n));
  }
  
  *(int n, int seed) {
    this((L) iotaZeroList(n), seed);
  }
  
  *(L<A> list) {
    this(list, 0);
  }

  *(L<A> list, int seed) {
    super(list);
    if (n == 0) ret with offset = 0;
    lsfr_start(seed);
    offset = value-1;
  }
  
  // copied from TripletLSFR.start
  void lsfr_start(int seed) {
    value = mod_31bit(seed, cycleLength)+1;
  }
  
  int postProcessLSFRValue(int i) {
    i += offset;
    ret i >= cycleLength ? i-cycleLength : i;
  }
}

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: 227 / 429
Version history: 21 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)
#1035214 - WeightlessShuffledIteratorWithSeed (working backup with external LSFR)