Alice Community  

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

Reply
 
Thread Tools Display Modes
Random Number Generator(school project due friday)
Old
Samo
Guest
 
Status:
Posts: n/a
Question Random Number Generator(school project due friday) - 05-31-2006, 06:41 AM

ok, i'm very short on time(have till friday), so plz respond asap.

how would i go about making a random number generator or if it can't be done, what could i use to replace it?
   
Reply With Quote
Old
lanceA
Guest
 
Status:
Posts: n/a
Default 05-31-2006, 09:28 AM

You may wish to recheck with your teacher and ask him/her if you can use Alice's built-in Random function. I'm surprised you were given an assignment to use this without it first being explained in class, or maybe part of your assignment was to investigate the functions included in Alice ?

The World object has a Random function.

Good luck.

Last edited by lanceA; 05-31-2006 at 09:37 AM.
   
Reply With Quote
Old
Samo
Guest
 
Status:
Posts: n/a
Default 05-31-2006, 02:15 PM

well, the thing is, we weren't taught it. this is our teacher's first time using alice so originally, our assignment was to just mess around with alice for the rest of the year since we aleady took the ap exam. after doing that for a week, she decicded to make us make a 10 min. long animation since we were all basically doing that. she pretty much just taught us the basics nd told us to experiment which was fine with all of us


about the random function, totally missed that. does it work like the random generator method in java?

also, how do i get the time function to work?
   
Reply With Quote
Old
lanceA
Guest
 
Status:
Posts: n/a
Default 05-31-2006, 06:34 PM

Alice's Random function returns a 6 digit double. You give it a range of numbers, i.e., minimum to maximum. All of the numbers it returns will be >= to min but < max. i.e., 2.45712, 0.39718, etc. depending upon your max and min values.

For Alice's timer function you need to do several things: create a class-level variable (used to track number of seconds left) and then create a method in your timer object which accepts the variable as a parameter and then decrements it.

If, as you indicated, your teacher has sort of 'turned you loose' to explore Alice with minimal instruction you might want to 'explore' with a friend or as part of a group of your classmates - there's power in numbers
   
Reply With Quote
Old
Samo
Guest
 
Status:
Posts: n/a
Default 05-31-2006, 10:44 PM

i'm better than the rest of my class(but not by much, either way, we all try to help eachother)

for the random thing, would i be able to make it pick anumber from 1-10 or something like that

and for the time thing, is there a tut on that? cause i don't really know how to do anything other more advanced than to allow u to steer something and haave the camera and other things follow

edit: also, how can i use a variable in more than one method?

Last edited by Samo; 06-01-2006 at 06:59 AM.
   
Reply With Quote
Old
lanceA
Guest
 
Status:
Posts: n/a
Default 06-01-2006, 07:09 AM

I normally wouldn't be doing this but since it's the end of the school year try this for your random number:

Creat a new world.

Place an If/Else statement in the world.myfirstmethod

Click the create a new variable button and name your variable randomNumber and select Number as its type. Click OK to close the Create New Local Variable window.

You should see your variable at the top of world.myfirstmethod.

Drag your randomNumber variable tile down to the If statement. A dialog box will appear asking you for a value. Select 1 (you will change this in the next step).

Select the world tile, click functions and scroll down to random number. Drag the random number tile to the set value tile and replace the number 1 with it.

Click more in the random number tile and set the minimum value to 1. Click more again and set your maximum number.

Place code in your If/Else construct to test your random numbers.

To test your program you will probably have to run it MANY times and you should (emphasis on the word "should") see close to a 50% split in the execution of your If/Else statement. If you simply test it one or 8 times you might see that the same code executes all the time.

Your earlier email mentioned that you just completed the AP CompSci Exams and therefore I assume you are aware that Java's random number generator leaves a great deal to be desired. I won't go into the details but if you studied AP Computer Science then you probably also know that the MBS (Marine Biology Simulation) program for that course uses a Singleton method for it's RandNumGenerator. This produces a "better" random number generator.

The only tutorial I know for the timer function is in the Alice textbook.

Good luck.
   
Reply With Quote
Old
Samo
Guest
 
Status:
Posts: n/a
Default 06-01-2006, 03:48 PM

thx, i appreciate it, i'll test tommorrow, didn't have time today

also, where would find the alice text book, and is there an online version
   
Reply With Quote
Old
lanceA
Guest
 
Status:
Posts: n/a
Default 06-02-2006, 05:20 AM

You can purchase the book from either the publisher, Prentice Hall, or Amazon ($45.00). Sometime in June Prentice Hall will be releasing a "Brief-Edition" of the textbook (approximately $26.00).

The book is not supposed to be accessable for free on the internet, however you can subscribe to www.safarix.com and have access to the content online. I've never used them so I can not comment on the service.

Last edited by lanceA; 06-02-2006 at 05:24 AM.
   
Reply With Quote
Old
Samo
Guest
 
Status:
Posts: n/a
Default 06-02-2006, 07:00 AM

ok, thx, i think i figured out the probability thing, but whenever i run the program it crashes

i'm not sure if u do this, but i've uploaded the file so u can help me figure it out
Attached Files
File Type: zip Space Colony Attack.zip (3.80 MB, 450 views)
   
Reply With Quote
Old
lanceA
Guest
 
Status:
Posts: n/a
Default 06-02-2006, 11:38 AM

I don't debug other people's programs but what you might want to do when you have an error in your program is begin by eliminating some of your code and see if you can isolate where the problem might be.

For example:

If you disable all "play sound" calls in your program and then run it you will find that your program does not crash.

If you then add the calls for sound back into your program one at a time and test each time you can possibly determine that the sounds in your 3 functions are not causing the program to crash.

That only leaves the sound effect being called in your world.myfirstmethod, SpaceDock play sound.

Good luck
   
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 ©2017, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.