I want to generate a random number in Befunge, from 0 to n, where n is an arbitrary number. How would I go about doing this?
I thought of trying this (this example has 2 chained chunks of code to show how it works):
v v
?#>?#>
1 1
+ +
> ^> ^
and repeating as needed, but I would need n copies of that chunk of code.
Is there a better way I can generate a random number like rand(0, 10) in other languages?
This snippet will mostly do what you want. (It brakes on 0.)
Note that in both my generator and yours the distribution is not flat; it is binomial. This block will make a random number with a smooth distribution from 0 to 2^n-1: