Programming Using the GWBASIC RND Command
Embed:
RND is a useful command in the programming language GWBASIC, especially for creating games and simulations. It can also be used with other varieties of BASIC, like QBASIC and Visual BASIC, but the syntax varies slightly in some situations. It is relatively easy to learn and apply to programming. Here is a simple example of using RND in GWBASIC:10 A = INT(RND * 10) + 1
20 PRINT A
As always in GWBASIC, you can type the RUN command and press enter to activate the program you have entered. This example sets the variable "A" to a random whole number (INT) between one and ten, then displays (PRINT) it on the screen. Ten and twenty are line numbers. However, this will produce the same number every time the program runs. To fix this, add the following command and try running the program again:
5 RANDOMIZE TIMER
This instructs the GWBASIC program to use the current time (down to the hundredth of a second) in the process of determining a random number, which prevents it from being the same each run. Using the line number "5" instructs GWBASIC to automatically place this command at the beginning of the program, before the previously-entered lines numbered 10 and 20.
The RND command doesn't have to be used with variables. The following commands all use RND directly, to create random sounds, numbers, and colors:
30 PRINT "Random Number, 0 to 50: "; INT(RND*50)
40 SOUND INT(RND * 200)+100, 5
50 COLOR INT(RND * 4), INT(RND * 4) + 4
Type COLOR 7, 0 and press ENTER to change back to white text over black, after running this program example. The SOUND command will work on most computers, but not all. Use the "LIST" command to view the entire program, then type "NEW" and press enter to clear it.
Here is an example of using the RND command to create a working, useful GWBASIC program. It lets you guess a number from one to twenty-five in up to four guesses, and provides hints as to whether the correct number is higher or lower. To end the program early, press the "CTRL" and "C" keys at the same time...
Programming Using the GWBASIC RND Command
You may also like...
- Programming: Creating Executables
- 12 Step Programs for Addition Recovery
- Do Abstinence-only Programs Work?
- Free for All Welfare Grant Programs Hurt...
- Alcohol Abstinence Programs; An Overview...
- Affiliate Programs, an Overview
- Recommendations for Animated Programs on...
- CMS Programs: Choosing the CMS Program t...
- Free Programs for Windows
- Why Affiliate Programs Are Right for You
Most Commented On



Mrs Mallick
Add a Comment
Posted on 05/16/2008 at 9:05:23 AM