Skip to content

Instantly share code, notes, and snippets.

@fnzainal
Last active September 23, 2021 12:29
Show Gist options
  • Save fnzainal/ac04c35527ff674daab4008d0ed34cfb to your computer and use it in GitHub Desktop.
Save fnzainal/ac04c35527ff674daab4008d0ed34cfb to your computer and use it in GitHub Desktop.
Dummy Data Generator Kotlin
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