Advertisement
RandomGuy32

generate_random_bit.mcfunction

Mar 30th, 2023
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. # Sets RNG_Random_Bit to either 0 or 1 with a 50% chance for each.
  2. execute if predicate charlottebuff:coin_flip run scoreboard players set RNG_Random_Bit rng 1
  3.  
  4. # Multiplies RNG_Random_Bit with the current RNG_Shift_Index to produce a bit mask (that's not the right word) with the previous value of RNG_Random_Bit at the current position and 0 everywhere else.
  5. scoreboard players operation RNG_Random_Bit rng *= RNG_Shift_Index rng
  6.  
  7. # Adds the aforementioned bit mask to the RNG_Output, producing one binary digit of randomness.
  8. scoreboard players operation RNG_Output rng += RNG_Random_Bit rng
  9.  
  10. # RNG_Shift_Index is doubled (or shifted left once, if you will) to advance the active position by one step.
  11. scoreboard players operation RNG_Shift_Index rng += RNG_Shift_Index rng
  12.  
  13. # RNG_Random_Bit is cleared for the next loop iteration
  14. scoreboard players set RNG_Random_Bit rng 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement