rndstore
Replaces what's in a cell with a random number between 0 and that value, with the same sign.
Facts
- Word
rndstore- Family
- Writing to memory
- Integer stack
- pops 1, pushes 0
- What it does
- Pops an address and replaces the cell with a random number between 0 and what it had, both included. With −5 the result is anywhere from −5 to 0.
- Cost
- Store divided by the divisor of each one, only if it writes
- Cost divisor
- ÷ 7
- Runs
- in the body of a gene (start or else), and only if the top of the boolean stack is true or the stack is empty
- Marks ties
- no
d rndstore pops the address d and replaces what's in the cell with a random integer between 0 and that number, both included. It takes no value from the stack: the top of the draw is whatever was already stored.
| Word | Stack afterwards |
|---|---|
50 | 50 |
rndstore | (empty); if cell 50 held 20, it now holds something between 0 and 20 |
That's why it almost always comes after a store that loads the top:
' turns after a random wait of 0 to 20 cycles
cond
*50 0 =
start
100 .aimdx store
20 50 store
50 rndstore
stop
cond
*50 0 >
start
50 dec
stopEach time the count reaches 0, the bot turns with .aimdx and draws a new wait, which dec counts down. If the draw gives 0, it turns again in the next cycle.
With a negative number the draw is symmetric: if the cell holds −5, it ends up with something between −5 and 0. That's what sets it apart from rnd, which with -5 gives −4 to −1. On a cell holding 0 it always gives 0.
If you only want a random number to use right away, rnd is more direct: 20 rnd 50 store draws in the same range, 0 to 20, as 20 50 store 50 rndstore. With negatives, as seen, the ranges differ.