Notice: My personal stance on AI generated artwork. Retweet and share if you agree. Let us discuss, and not immediately scream bloody murder.

Now Viewing: API question; randomization
Keep it civil, do not flame or bait other users. If you notice anything illegal or inappropriate being discussed, contact an administrator or moderator.

Strahan - Group: Member - Total Posts: 85
user_avatar
API question; randomization
Posted on: 06/08/25 04:55PM

Hi.

I wanted to be able to pull X amount of random images for a given tag set. Is there a built in method for that? In my Googling I saw someone reference a random function but they complained it was blank, and it still is. So far what I came up with is basically do an initial query on the tag set and get the count attribute from the posts parent. Then I can loop on the number of images needed and in the loop set int chosen to random between 0 and Math.Max(count attribute, 20000). Then I just get pid chosen limit 1, then sleep for a little to prevent hammering on the server.

I guess that'd work, but it'd be way nicer to be able to do like &tags=whatever&limit=6&random or something. Is there something like that?

Thanks!



Jerl - Group: The Real Administrator - Total Posts: 7007
user_avatar
Posted on: 06/08/25 06:28PM

The "sort:random" metatag works on the API.



Strahan - Group: Member - Total Posts: 85
user_avatar
Posted on: 06/13/25 06:57AM

Thanks!



add_replyAdd Reply