[vcf-midatlantic] Random numbers
Kelly Leavitt
kelly at catcorner.org
Fri Apr 7 13:28:04 EDT 2017
I don't know why the result is always an even number, but I suspect that this will always return the same sequence of numbers. You have to randomize the seed value of the argument to the rnd function early in the program or it will return the same sequence of numbers every time you turn the machine on.
>From http://www.hoist-point.com/applesoft_basic_tutorial.htm#random_numbers_section
AppleSoft BASIC RND(1) function generates a pseudo-random number between 0 and 1 (excluding 1). Random numbers are used in games, computer modeling and math applications. Let's look at small program which simulates throwing a dice 20 times, generating values from 1 to 6, and prints the result.
As you run this program again and again, you notice that it generates exactly the same set of numbers every time. The numbers you get from RND(1) function aren't truly random (this is why they are called pseudo-random!): computer uses an algorithm to generate them, and when program restarts, the same algorithm produces the same sequence of values. To make it generate a new sequence, you must re-initialize the random number generator by calling RND with a negative value (called random seed). Each specific value will result in different random number sequence generated afterwards.
________________________________
From: vcf-midatlantic <vcf-midatlantic-bounces at lists.vintagecomputerfederation.org> on behalf of Evan Koblentz via vcf-midatlantic <vcf-midatlantic at lists.vintagecomputerfederation.org>
Sent: Friday, April 7, 2017 1:05 PM
To: vcf-midatlantic
Cc: Evan Koblentz
Subject: [vcf-midatlantic] Random numbers
Got a line in my game to pick random whole numbers between 1-38. I use
these numbers to determine the secret spot a player must find.
It says:
R=INT(RND(1)*38)+1
I read about RND in the Apple II programming manual but I determined the
exact code from a Google search (stack overflow method...)
Problem: it's only giving me even numbers. No odd numbers. Why? And how
do I fix that?
________________________________
Evan Koblentz, director
Vintage Computer Federation
a 501(c)(3) educational non-profit
evan at vcfed.org
(646) 546-9999
www.vcfed.org<http://www.vcfed.org>
facebook.com/vcfederation
twitter.com/vcfederation
instagram.com/vcfederation
More information about the vcf-midatlantic
mailing list