FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

MATHEMATICS

Use a better random function


There was some discussion of methods for big random numbers, but RND _does_ work in the mini runtime. Of course you have to live with the limitation (1-32767).

If you need numbers up to 65535 try replacing your code:

test& = FN RANDOM
test& = VAL(UNS$(test&))
test& = (test& * _maxitem) / 65536 + 1

by:

test&=FN RANDOM
IF test&<0 THEN test&=test&+65536
test&=((test&*_maxitem)>>16)+1

which is much faster since there are no string conversions. This also works in the mini runtime.

Finally, the answer to your question why the "one-line" version of a code snippet is slower than a three-line unrolled version is a compiler mystery.
Disassembly of the generated 68K code shows 8 calls (JSR) to the runtime for the one-line, and only 5 for the apparently equivalently three-line.

Robert Purves