Last active
September 23, 2021 12:29
-
-
Save fnzainal/ac04c35527ff674daab4008d0ed34cfb to your computer and use it in GitHub Desktop.
Dummy Data Generator Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class BaseFragment : Fragment(){ | |
fun generateDummy(): List<Contact> { | |
val list = mutableListOf<Contact>() | |
for (i in 0 until 10){ | |
list.add( | |
Contact( | |
getRandomString()+" "+getRandomString(), | |
getRandomString(), | |
"+62"+getRandomNumber(), | |
"", | |
"", | |
id = (1..20).random() | |
) | |
) | |
} | |
return list | |
} | |
fun getRandomString() : String { | |
val length = (10..20).random() | |
val allowedChars = ('a'..'z') | |
return (5..length) | |
.map { allowedChars.random() } | |
.joinToString("") | |
.replaceFirstChar{first -> first.uppercase()} | |
} | |
fun getRandomNumber() : String { | |
val length = (8..12).random() | |
val allowedChars = ('0'..'9') | |
return (1..length) | |
.map { allowedChars.random() } | |
.joinToString("") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment