I need to get a random element of a specific result set. I have a working XPath expression and need the same thing in the other one. This is what i have right now:
The working one:
ad/item[[eval:('Math.floor(Math.random()*7)+1')]]
and this is the one I need. It needs also the random in but with the filter on recommended:
query/results/json/feed/entry[contains(gsx_type/_t,'recommended')]
I know that if i just want a number I can put it like this:
query/results/json/feed/entry[contains(gsx_type/_t,'recommended')][3]
or
query/results/json/feed/entry[(contains(gsx_type/_t,'recommended')) AND (item = 3) ]
But this is not what I need. I have 12 pictures that are recommended so maybe if someone knows what to write to make this work that would be really great!
If I understood you correctly what you want to achieve, you can simply combine both:
query/results/json/feed/entry[contains(gsx_type/_t,'recommended')][eval:('Math.floor(Math.random()*7)+1')]
However, this eval:()
function looks very strange to me, you might also be able to use a random module provided by your processor or call a functions differently. Also, if you have 12 pictures you might want to change the 7
to 12
.