strShuffle function

String strShuffle(
  1. String str
)

Randomly shuffles the received string and returns it.

Implementation

String strShuffle(String str) {
  final List<int> codePoints = str.runes.toList();
  final Random random = Random();

  for (int i = codePoints.length - 1; i > 0; i--) {
    int j = random.nextInt(i + 1);
    int temp = codePoints[i];
    codePoints[i] = codePoints[j];
    codePoints[j] = temp;
  }

  return String.fromCharCodes(codePoints);
}