Useful subroutines will be added for download here. You'll probably have to modify the line numbers to fit them into your program. You might have to rename the variables too, if they interfere with an existing program you'd like to slot the subroutines into.
Random Number Generator
Size 0kb, downloads 242.
Here's a simple random number generator. If you want X to be a random number between, say, 1 and 6, you would call it like this: GOSUB 200 LET X=1+R-R/6*6 To set the seed, simply set R to a number between 0 and 6546 before calling the subroutine. You may need to ask the user of your program to "think of a number" to get one. Alternatively, you can set your own seed for procedural world generation. (read more...)
Euclidean Distance Calculation
Size 0kb, downloads 243.
This subroutine calculates the Euclidean distance ("as the crow flies") between two points on a flat plane. The coordinates should be in the variables V, W, X and Y, representing the points (v,w) and (x,y). The variable U will be trashed for temporary workspace, and Z will hold the distance. It is important to note that because of TinyBASIC's reliance on integer arithmetic, and the lack for mathematical functions like square root, the result will be approximate. (read more...)
Wichmann-Hill Random Number Generator
Size 0kb, downloads 189.
Here's a random number generator that uses the Wichmann-Hill method. It should result in better output than the simpler Random Number Generator posted elsewhere. The disadvantage over the simple generator is that it takes up four variables instead of one: W is the random number returned, and X , Y and Z are the seeds. Before you call the random number generator, you must set X, Y and Z to non-zero values. Afterwards, use the subroutine as follows: ... (read more...)