Is there a command block command, or something to do with redstone that activates randomly? [duplicate]

i'm trying to create a redstone game that a has component that has to be random, and i was wondering, if there is a command block command, that when the command block is activated, has a 50% chance of creating a temporary redstone charge? If not, then is there a way to do it with redstone?

I tried making it so it is the same every time, but that would get boring.

Any help would be appreciated.

i'm using 1.13


Solution 1:

Place an impulse command block and 2 armor stands on top of it. Tag one of the armor stands with some tag.

Use this command in the command block, you can use any other tag, too, but it has to be the same as one of your armor stands. I used the tag win:

/execute as @e[type=minecraft:armor_stand,sort=random,limit=1,distance=..1] if entity @s[tag=win]

The command will randomly select one of the two armor stands and execute as that armor stand. It then tests if it has the win tag.

Use a comparator to get your redstone signal. You can have an observer obeserve the comparator if you want redstone pulses instead.

You can easily vary the chance of winning by using more armor stands, for a 60% chance of winning you could use 5 armor stands and tag 3 of them.