Computer Science Canada

Randomizing Varible! PLEASE HELP!

Author:  TopBypass [ Tue Jan 22, 2008 7:59 pm ]
Post subject:  Randomizing Varible! PLEASE HELP!

I have made variables (a, b and c) and now i need to have them be picked but completely randomly and i am using Rand.Int but it wont work!! I really need help with this its for a final!! Thank you sooo much!

Author:  michaelp [ Tue Jan 22, 2008 8:03 pm ]
Post subject:  RE:Randomizing Varible! PLEASE HELP!

What do you mean by "won't work?" Is is the same number every time, a, b, and c are all the same? Did you test the variables using "put a" or "put b" or "put c"?
If you want them completely random, just use the arguments 1 and a really big number.

Author:  Gooie [ Tue Jan 22, 2008 8:03 pm ]
Post subject:  Re: Randomizing Varible! PLEASE HELP!

Use something like this.

code:

RandomChoice := Rand.Int (1, 3)

if RandomChoice = 1 then
    put "cat"
elsif RandomChoice = 2 then
    put "dog"
elsif RandomChoice = 3 then
    put "fish"
end if


A case would be better though.

Author:  TopBypass [ Tue Jan 22, 2008 8:24 pm ]
Post subject:  Re: Randomizing Varible! PLEASE HELP!

Still wont work, im getting an error. This is what i am trying to do:

Write a program that plots points at A(300, 50), B(50, 500) and C(550, 500) - I finished this here is how i did it:

code:
Draw.Dot (300, 50, black)
Draw.Dot (50, 500, black)
Draw.Dot (550, 500, black)


Now i need to:
randomly choose either A, B or C (lets say it was A) and plot a new point, Q, which is half way between P and A.

Author:  TopBypass [ Tue Jan 22, 2008 8:38 pm ]
Post subject:  RE:Randomizing Varible! PLEASE HELP!

Im still confused and i really do need this as quickly as possible so please help me! Thank you!

Author:  TopBypass [ Tue Jan 22, 2008 8:49 pm ]
Post subject:  RE:Randomizing Varible! PLEASE HELP!

Alright i messed up something. Here is what i need from the start. I need to plot a point called A as a variable. A has to be a certain point BUT I HAVE NOOOO IDEA HOW TO DO THIS. I have tried making its value Draw.Dot (number, number, color) but that wont work either.

Author:  Gooie [ Tue Jan 22, 2008 9:06 pm ]
Post subject:  Re: Randomizing Varible! PLEASE HELP!

Alright, well what data type are is A?

Author:  TopBypass [ Tue Jan 22, 2008 9:16 pm ]
Post subject:  RE:Randomizing Varible! PLEASE HELP!

I defined it as an int

Author:  Gooie [ Tue Jan 22, 2008 9:25 pm ]
Post subject:  Re: Randomizing Varible! PLEASE HELP!

Your first problem is that an Integer can't store two values (an ordered pair (x,y)).

Author:  TopBypass [ Tue Jan 22, 2008 9:26 pm ]
Post subject:  RE:Randomizing Varible! PLEASE HELP!

Also do you know how to use putpixel? It says i am too use it but i cannot find it in turing.

Author:  TopBypass [ Tue Jan 22, 2008 9:31 pm ]
Post subject:  RE:Randomizing Varible! PLEASE HELP!

What would i use than? Would a string work?

Author:  Gooie [ Tue Jan 22, 2008 9:33 pm ]
Post subject:  Re: Randomizing Varible! PLEASE HELP!

I don't believe putpixel exists in Turing. I searched documentation, the internet, compsci, and I can declare a variable by that name. Are you sure your teacher isn't confused with another language?

Author:  TopBypass [ Tue Jan 22, 2008 9:35 pm ]
Post subject:  Re: Randomizing Varible! PLEASE HELP!

Alright so far i can pick a random point and a random variable in which case it draws a dot in its location. Here is the code for that.

code:
var int_ax :int := 300
var int_ay :int := 50
var int_bx :int := 50
var int_by :int := 500
var int_cx :int := 550
var int_cy :int := 500
var int_p :int := Rand.Int (1, 1000)
var random :int := Rand.Int (1, 3)


Draw.Dot (int_ax, int_ay, black) %This is my A
Draw.Dot (int_bx, int_by, black) %This is my B
Draw.Dot (int_cx, int_cy, black) %This is my C

Draw.Dot (int_p, int_p, black) %This is my P

loop
if random = 1 then
    Draw.Dot (int_ax, int_ay, black)
end if
if random = 2 then
    Draw.Dot (int_bx, int_by, black)
end if
if random = 2 then
    Draw.Dot (int_cx, int_cy, black)
end if
end loop


Now what i want to do is make it so when it picks a random point (A or B or C) it makes a dot in between P and the randomly choicen one.

EDIT: It might be but its his exact type. "Pick a random point to start, call it P and plot it using putpixel"

Author:  TopBypass [ Tue Jan 22, 2008 9:41 pm ]
Post subject:  RE:Randomizing Varible! PLEASE HELP!

Also the midpoint can be found by following this equation:

Posted Image, might have been reduced in size. Click Image to view fullscreen.

Author:  TopBypass [ Tue Jan 22, 2008 9:44 pm ]
Post subject:  RE:Randomizing Varible! PLEASE HELP!

I think i have found one of my problems. I have giving int_p a specific Rand.Int point. Instead i need it to form anywhere on the page. Is this possible?

EDIT: By the way you have been a great help! Just wanted to say that it is not going unnoticed and i am completely grateful Smile

Author:  HeavenAgain [ Tue Jan 22, 2008 9:58 pm ]
Post subject:  RE:Randomizing Varible! PLEASE HELP!

ahhhhhhhhh i know this, Sierpinski Triangle !!!
anyways, i see that... you've been struggle for a quite long time...... and here is what i have for you
you have to make a random dot everytime, so you have to call to the random variable everytime, so it becomes
code:

loop
 var myRandomNumber : int := Rand.Int (1, 3)
end loop

now... thats one of the problem you have, 2nd, you have to get the mid point of the current X and Y, so then you have to store them into a variable of course
code:
var currentX := 0
var currentY := 0
loop
 var myRandomNumber : int := Rand.Int(1,3)
 currentX = (currentX + x1) div 2
 currentY = (currentY + y1) div 2
 Draw.Dot (currentX, currentY, black)
end loop

this is only for 1 case... and i think i better leave the rest to you...

by the way, you wouldnt happen to go to dr norman bethune ci do you? Rolling Eyes

Author:  TopBypass [ Tue Jan 22, 2008 10:03 pm ]
Post subject:  RE:Randomizing Varible! PLEASE HELP!

Alright i will try that! Ohh and no sorry i don't.

EDIT: I've added you on msn if you don't mind.

Author:  TopBypass [ Tue Jan 22, 2008 10:26 pm ]
Post subject:  Re: Randomizing Varible! PLEASE HELP!

Update, took another approach!

code:
var int_ax :int := 300
var int_ay :int := 50
var int_bx :int := 50
var int_by :int := 500
var int_cx :int := 550
var int_cy :int := 500
var int_p :int := Rand.Int (0, 0)
var random :int

Draw.Dot (int_ax, int_ay, black) %This is my A
Draw.Dot (int_bx, int_by, black) %This is my B
Draw.Dot (int_cx, int_cy, black) %This is my C

Draw.Dot (int_p, int_p, black) %This is my P

loop
random := + Rand.Int (1, 3)
if random = 1 then
    Draw.Dot (int_ax, int_ay, black)
end if
if random = 2 then
    Draw.Dot (int_bx, int_by, black)
end if
if random = 2 then
    Draw.Dot (int_cx, int_cy, black)
end if
end loop

Author:  TopBypass [ Tue Jan 22, 2008 10:34 pm ]
Post subject:  Re: Randomizing Varible! PLEASE HELP!

Update

code:
var int_ax :int := 300
var int_ay :int := 50
var int_bx :int := 50
var int_by :int := 500
var int_cx :int := 550
var int_cy :int := 500
var int_px :int := 0
var int_py :int := 0
var random :int

Draw.Dot (int_ax, int_ay, black) %This is my A
Draw.Dot (int_bx, int_by, black) %This is my B
Draw.Dot (int_cx, int_cy, black) %This is my C

Draw.Dot (int_px, int_py, black) %This is my P

loop
random := + Rand.Int (1, 3)
if random = 1 then
    int_px := (int_px + int_ax) div 2
    int_py := (int_py + int_ay) div 2
end if
if random = 2 then
    int_px := (int_px + int_bx) div 2
    int_py := (int_py + int_by) div 2
end if
if random = 2 then
    int_px := (int_px + int_cx) div 2
    int_py := (int_py + int_cy) div 2
end if
end loop

Author:  TopBypass [ Tue Jan 22, 2008 10:39 pm ]
Post subject:  Re: Randomizing Varible! PLEASE HELP!

Another update

code:
var int_ax :int := 300
var int_ay :int := 50
var int_bx :int := 50
var int_by :int := 500
var int_cx :int := 550
var int_cy :int := 500
var int_px :int := 0
var int_py :int := 0
var random :int

Draw.Dot (int_ax, int_ay, black) %This is my A
Draw.Dot (int_bx, int_by, black) %This is my B
Draw.Dot (int_cx, int_cy, black) %This is my C

Draw.Dot (int_px, int_py, black) %This is my P

loop
random := + Rand.Int (1, 3)
if random = 1 then
    int_px := (int_px + int_ax) div 2
    int_py := (int_py + int_ay) div 2
end if
if random = 2 then
    int_px := (int_px + int_bx) div 2
    int_py := (int_py + int_by) div 2
end if
if random = 2 then
    int_px := (int_px + int_cx) div 2
    int_py := (int_py + int_cy) div 2
    Draw.Dot (int_px, int_py, black)
end if
end loop

Author:  TopBypass [ Tue Jan 22, 2008 10:45 pm ]
Post subject:  RE:Randomizing Varible! PLEASE HELP!

Fixed it..YAY!!!

Author:  Clayton [ Tue Jan 22, 2008 10:47 pm ]
Post subject:  RE:Randomizing Varible! PLEASE HELP!

Um... wow. Quintuple post anyone? From now on, use the goddamn edit button. For the love of god.

Author:  Euphoracle [ Wed Jan 23, 2008 1:13 am ]
Post subject:  RE:Randomizing Varible! PLEASE HELP!

Either someone wants to get into the Member's Lounge (there's nothing there; stop trying, etc), or they are really happy... or they use MSN too much and don't understand the purpose of a forum... or the edit button for that matter.

I can keep ranting, so I'll stop here Smile


: