How can I randomly select every second/third entity of a kind?

I have decided that I don't like standing in front of a mob spawner for quite a while in order to reach level 30. Seeing that I don't (yet) have an Enderman farm (or a Pigman farm), I wondered if I can't simply increase the XP I get from everything by about 50% using command block magic to summon more of them.
The page for Experience states that most XP orbs have values of 1, 3, or 7, and I'll limit my contraption to working with these three.
I have set up a scoreboard objective to distinguish freshly dropped XP orbs and their value using
scoreboard players set @e[type=XPOrb] XP 1 {Age:10s,Value:1s}
I would like to either summon a copy of these orbs at their position, or simply double their value, but only for about half of them, which brings me to my question:
How can I randomly select only half of them for use with execute -> summon
or entitydata
? Ideally, this should be random on an entity basis, rather than "globally" (i.e. using time%2
), in order to make the increase smoother.
Best Answer
Well, it would be difficult to select a specific proportion of entities. One thing you could do, though, would be to tag each xp orb of a certain size using the data tag {Value:Xb}
, then use a /entitydata
command to increase the each orb's value by one (or however much you want, just make sure the resulting orb wont be tagged by another command block).
Alternatively, if selecting half is necessary, you can testfor all unmarked xp orbs, then run the comparator output from it to a certain number of command blocks based on the strength of signal, so that there's one command block per 2 xp orbs, each with the @r[type=XPOrb] command to activate once and duplicate the appropriate number of orbs, then another to mark all the rest so that they wont be doubled on subsequent runs, or counted so that the redstone signal doesn't exceed 16.
Pictures about "How can I randomly select every second/third entity of a kind?"



Excel time saver: Select every odd row (or all even rows) - Doctor Excel #086
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Karolina Grabowska, Name Name, Felicity Tai, William Fortunato