Advertisement
NubeColectiva

Como Generar un String Aleatorio con Kotlin (2 Maneras)

Apr 16th, 2023
1,590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.45 KB | None | 0 0
  1. fun generarStringAleatorio1() {
  2.  
  3.         val string = UUID.randomUUID().toString().substring(0, 12);
  4.  
  5.         Log.e("String Aleatorio 1: ", string);
  6.  
  7. }
  8.  
  9. fun generarStringAleatorio2() {
  10.  
  11.         val caracteres = ('A'..'Z') + ('a'..'z') + ('0'..'9');
  12.         var string = ""
  13.         for(i in (1..10)){
  14.             string += caracteres[(Math.random() * (caracteres.size - 1)).roundToInt()]
  15.         }
  16.         Log.e("String Aleatorio 2: ", string);
  17. }
Tags: Kotlin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement