Last active
March 11, 2023 05:13
-
-
Save hadiyarajesh/d168cf8a4f5de985c2cdc179b7918214 to your computer and use it in GitHub Desktop.
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
import kotlin.random.Random | |
data class Post( | |
val postId: Long, | |
val caption: String?, | |
val likesCount: Int, | |
val isLiked: Boolean, | |
) | |
fun main() { | |
// Create a sequence generator that will generate given sequence | |
val postGenerator = generateSequence { | |
Post( | |
// postId is a 8 digit Long value | |
postId = Random.nextLong(10000001, 88888888), | |
caption = | |
buildString { | |
// Repeat the same caption randomly about 1-5 times. | |
val randomValue = Random.nextInt(1, 5) | |
repeat(randomValue) { | |
append("Sample caption") | |
append(" ") | |
} | |
}, | |
likesCount = Random.nextInt(100, 500), | |
isLiked = Random.nextBoolean() | |
) | |
} | |
// Generate sequence of posts and take 50 posts from it | |
val posts = postGenerator.take(50) | |
// Print each posts on console | |
posts.forEach { println(it) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment