Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Problems with Random Whole Numbers...
Old
rrocks1241
Guest
 
Status:
Posts: n/a
Default Problems with Random Whole Numbers... - 03-14-2008, 02:03 AM

I have a program that I have to complete where it's basically a guessing game.
Alice picks a random number from 1 to 40,
then the user is asked to pick a number, to try to match the random one.
If the number is too high, it will say "Too high"
if the number is too low, it will say "too low"
if the number is the same as random, then it will let the user know as such.

However, my problem is that sometimes the random number will be a decimal.
Like, I will choose 8 and it will be too low, and if I choose 9 it will say "too high".
I have tried setting the variable "RandomNumber" as (ceiling(randomnumber[minimum=0][maximum=5]integerOnly=true)
I have tried with the integer false.
I have tried with the floor function.
I have tried with the round function.

I have also tried just setting:
(RandomNumber[min=0][max=40])
and then I would do
(RandomNumber set value to (ceiling(RandomNumber)))
and I would try with floor and round as well...

none of these have worked!
I have tested so many times, and I'm just stumped.

thanks so much for your time,

-rrocks
   
Reply With Quote
Problems with random whole numbers
Old
hgs
Guest
 
Status:
Posts: n/a
Default Problems with random whole numbers - 03-14-2008, 01:10 PM

I don't know why this is happening, and so far I've not tried to replicate it. I'd rewrite the testing code to be "too low" if it is less than r - 0.5 "too high" if it is greater than r + 0.5 and where r is your random generated integer, document that this is to work around a bug.
   
Reply With Quote
Old
DickBaldwin
Guest
 
Status:
Posts: n/a
Default 03-14-2008, 09:13 PM

Quote:
Originally Posted by rrocks1241 View Post
I have a program that I have to complete where it's basically a guessing game.
Alice picks a random number from 1 to 40,
then the user is asked to pick a number, to try to match the random one.
If the number is too high, it will say "Too high"
if the number is too low, it will say "too low"
if the number is the same as random, then it will let the user know as such.

However, my problem is that sometimes the random number will be a decimal.
Like, I will choose 8 and it will be too low, and if I choose 9 it will say "too high".
I have tried setting the variable "RandomNumber" as (ceiling(randomnumber[minimum=0][maximum=5]integerOnly=true)
I have tried with the integer false.
I have tried with the floor function.
I have tried with the round function.

I have also tried just setting:
(RandomNumber[min=0][max=40])
and then I would do
(RandomNumber set value to (ceiling(RandomNumber)))
and I would try with floor and round as well...

none of these have worked!
I have tested so many times, and I'm just stumped.

thanks so much for your time,

-rrocks
See http://www.alice.org/community/showthread.php?t=983

Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials: http://www.dickbaldwin.com/toc.htm
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 03-15-2008, 11:09 AM

Also note that there is a bug in the random number generator in Alice and you always need to make sure any test is made on floating point numbers (multiply both numbers by 1.0 before the test).

This bug was documented in the bug list and there are several posting in the forum. It also is very inconsistant - most of the time (>80% in the case of the one class test I'm aware of) the bug does not occur.
   
Reply With Quote
Thanks so much!
Old
rrocks1241
Guest
 
Status:
Posts: n/a
Default Thanks so much! - 03-25-2008, 03:38 PM

Thanks so much for your help!!
I got the program to work most of the time I tested it

again, thanks
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2021, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.