# Is it possible to get total number of existing image ID's?

Im making a random image generator, and i made it simple:

`repeat script.Parent.Parent.ImageLabel.Image = "rbxassetid://"..math.random(1,x) task.wait(0.1) until script.Parent.Parent.ImageLabel.IsLoaded`

But I don’t know how I’m supposed to get the total number of existing imageIDs and put it at x spot.
Is it even possible?

1 Like

I dont think thats possible…
[character limit]

2 Likes

To answer your question on how to get an upper bound for `x`, upload an image asset yourself and take the numeric ID from that.

2 Likes

But the number of images increases dynamically, so when somebody creates another image then there would be no chance for it to randomize

1 Like

Thats the best you can do tho

or make x increase with +1 every second and save it in DSS but thats just nonsense

1 Like

Yep, good catch! If you wanted to have `x` dynamically update, couple things you could do…

• Systematically upload a new asset and get it’s id. This would involve some external web services, I personally wouldn’t know where to start with that. This would be horribly complicated

• Create a function to “search” for `x`

1. Write a “guess” for `x` that would be insanely large.
2. Try this, see if it is a valid Id
3. If it is not valid, divide `x` by `2` and try again.
4. Eventually, you will have a value `x` that is invalid and a value `x/2` that is valid. You now have a range for an upper bound
5. Split the range of `[x/2, x]` down the middle (`mid = (x + (x/2))/2 = (3x/4)`). Query this value.
6. If `mid` is valid, then you know the upper bound exists in `[(3x/4), x]`. If it is invalid, you know it is in `[x/2, (3x/4)]`. Repeat this as an interative process until you reach a range of size 1. This is your final value.

Now, this logic presumes that `"rbxassetid://"..x"` is valid for all values of x from 1 to `x` (which is not the case I’m afraid - infact, a majority of your “guesses” will be invalid)

Conclusion being… do you really need to do this? Is there a simpler solution that will achieve the same/similair outcome for you?

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.