diceware: switch to buildString lambda

This commit is contained in:
Harsh Shandilya 2021-12-21 17:21:54 +05:30
parent 0830499c6c
commit 95075bd1d0
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80

View file

@ -23,15 +23,12 @@ constructor(
/** Generates a passphrase with [wordCount] words. */
public fun generatePassphrase(wordCount: Int, separator: Char): String {
return StringBuilder()
.apply {
repeat(wordCount) { idx ->
append(wordMap[die.rollMultiple(DIGITS)])
if (idx < wordCount - 1) append(separator)
}
return buildString {
repeat(wordCount) { idx ->
append(wordMap[die.rollMultiple(DIGITS)])
if (idx < wordCount - 1) append(separator)
}
.toString()
.trimEnd()
}
}
private companion object {