Skip to content
Advertisement

Generate a random according to criteria [closed]

I have a JSON File (ArrayList) with some Restaurants and km(miles) from my Workplace to the Restaurant. The User can choose how far away the Restaurant should be (5km, 10km..) after that should the Applikation chooses the one Restaurant from the list, which inside this km is. So I need a random generator that, choose a Restaurant according to my criteria. The Result should show a Restaurant with “Name, Address, km, phone number and day offs”.

Can someone support me? I’m new in this Business.

JSON File

Main

AdapterJSON which reads data from JSON File

Advertisement

Answer

You can:

  • order your list by distance.
  • filter items in the range needed
  • create a random int between 0 and the size of the filtered items (minus 1)
  • pick the filtered item in the random position
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement