I have declared an object class ImageStore, where there is imagesNamesMap containing 5 key-value pairs, I want to randomly choose 4 key-value pairs out of the imagesNameMap then randomly assign the keys and value between those 4.
ImageStore
object ImageStore {
val imagesNamesMap= hashMapOf(
R.drawable.africa to "Africa",
R.drawable.asia to "Asia",
R.drawable.europe to "Europe",
R.drawable.antartica to "Antarctica",
R.drawable.airplane to "Airplane"
)
val selectedImagesNamesMap = imagesNamesMap.toList().take(4).toMap()
}
Example
val imagesNamesMap= hashMapOf(
R.drawable.africa to "Africa",
R.drawable.asia to "Asia",
R.drawable.europe to "Europe",
R.drawable.antartica to "Antarctica",
R.drawable.airplane to "Airplane"
)
// randomly choose 4 out of imagesNamesMap
val random4 = hashMapOf(
R.drawable.africa to "Africa",
R.drawable.asia to "Asia",
R.drawable.europe to "Europe",
R.drawable.airplane to "Airplane"
)
// reassign key and values
val random4 = hashMapOf(
R.drawable.africa to "Asia",
R.drawable.asia to "Africa",
R.drawable.europe to "Airplane",
R.drawable.airplane to "Europe"
) <--- I want this map... How to get so?
update the
ImageStoreobject like thisnow you can get the map using