Search code examples
androidkotlinandroid-fragmentsurlandroid-imageview

How could you do a Get Random to get images from a url?


I am making an application and I want one of the Fragments to have an ImageView and the image to be taken from a URL that connects to my VPS. I would like you to tell me how can I take a random url from the img folder of the url https://imagerandom.com/img (that url is an example) and project it to ImageView


Solution

  • Method 1

    If you already have a bunch of images you can follow below steps:-

    1)first import the all images in the file/code.

    2)then store their names in the array or list of string/integer depending upon the name type.

    3)then uses the random function to generate index of list/array.

    4)then store the random index in some variable and you can use that to have a random images.

    Method 2

    On internet a lot of websites are available for generating random pictures

    I used "picsum" and help me a lot in various web application for testing

    Link for the site:-

    https://picsum.photos/

    hope you gonna love it !!