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
Reply


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