The TransCompilator

Solved LeetCode program · 347 of 1,000

#0470 · Implement Rand10() Using Rand7()

Medium Math chunk-07.md

Original English source

Keep a shared state of 0. Keep a shared value of 0. Keep a shared group of 0. Keep a shared result of 0.
To roll. Increase state by 1. If state is more than 7, set state to 1.

To draw. Set value to 0.
Repeat while value is less than 1 or value is more than 40.
Roll. Set group to state minus 1. Roll. Set value to group times 7 plus state. Set result to (value minus 1) modulo 10 plus 1.

Draw. Show result.

Open in Playground Browse all 1,000 problems

Expected stdout

2