Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 help with randint
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
gugiey




PostPosted: Sat Dec 23, 2006 2:34 am   Post subject: help with randint

ok well im tring to make a water melon with seeds in it and i want each time u run the program the seeds go diffrent places.. thing is they wont stay in the watermelon slice.. and when they do they seem to be close together.. can any one help?

code:

var maxrad := 300
var x, y : int
var angle := 40
x := 100
y := 100
for radius : 1 .. maxrad
drawfillarc (x, y, radius, radius, 0, angle, green)
end for
maxrad := 280
angle := 40
x := 100
y := 100
for radius : 1 .. maxrad
drawfillarc (x, y, radius, radius, 0, angle, red)
end for
for i : 1..5
randint (x,170,250)
randint (y,170,250)
drawfilloval (x,y,6,6,black)
end for
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Sat Dec 23, 2006 11:22 am   Post subject: (No subject)

First thing: stop using randint. randint is a procedure that takes a variable argument and mercilessly changes its value within. This is generally considered bad coding practice as you have no idea what's happening to your precious variable. Instead, use Rand.Int(), a function that returns a value as opposed to modifying the outside program.

Second Thing: this is going to take some math, perhaps you should try and find the formula of the curve (quadratics if you haven't taken grade 10 math yet) and work around with it to keep the points within the slice?
gugiey




PostPosted: Wed Dec 27, 2006 8:24 pm   Post subject: huh

huh
Ultrahex




PostPosted: Wed Dec 27, 2006 9:31 pm   Post subject: (No subject)

minute, what does huh mean?
Clayton




PostPosted: Wed Dec 27, 2006 9:33 pm   Post subject: (No subject)

what kind of reply is "huh"?

instead, explain what you are having problems with. We usually ask that you keep your posts at an intelligent level here (Off Topic is a different area altogether though Razz)
Ultrahex




PostPosted: Wed Dec 27, 2006 9:34 pm   Post subject: (No subject)

minute, why does he need to explain, man im so confused.... why does programmin have to be so damn confusing...

and minute intellgeient means how domb you are right?
gugiey




PostPosted: Wed Dec 27, 2006 11:08 pm   Post subject: (No subject)

Freakman wrote:
what kind of reply is "huh"?

instead, explain what you are having problems with. We usually ask that you keep your posts at an intelligent level here (Off Topic is a different area altogether though Razz)


srry lol im haveing truble with what ur first post said with the Rand.Int()

like what the () mean and stuff can u exlain it a little more
[Gandalf]




PostPosted: Wed Dec 27, 2006 11:45 pm   Post subject: (No subject)

The () simply say that it's a function or procedure. The difference between randint() and Rand.Int() is that Rand.Int() is a function while randint() is a procedure. A function is just like a procedure, except it also returns a value. So, say your function blah() always returned the number 5. Well, you could then output blah() or store it in a variable, like so:
code:
var number : int := blah %or
put blah

The result would be 5 being stored in the number variable, and "5" being displayed on the screen.

The last thing I would like to clarify is that you're not actually outputting/storing blah(), like a variable, instead you're outputting/storing the value returned by it. Just read over that a few times and it should make sense.

Do you understand things more now? In the future, you'll get more helpful responses if you make more intelligent posts, not "huh." Surprised
Sponsor
Sponsor
Sponsor
sponsor
gugiey




PostPosted: Wed Dec 27, 2006 11:47 pm   Post subject: (No subject)

[Gandalf] wrote:
The () simply say that it's a function or procedure. The difference between randint() and Rand.Int() is that Rand.Int() is a function while randint() is a procedure. A function is just like a procedure, except it also returns a value. So, say your function blah() always returned the number 5. Well, you could then output blah() or store it in a variable, like so:
code:
var number : int := blah %or
put blah

The result would be 5 being stored in the number variable, and "5" being displayed on the screen.

The last thing I would like to clarify is that you're not actually outputting/storing blah(), like a variable, instead you're outputting/storing the value returned by it. Just read over that a few times and it should make sense.

Do you understand things more now? In the future, you'll get more helpful responses if you make more intelligent posts, not "huh." Surprised


yes a understand it a little better but i still dont understand how to put that in to the program
Hackmaster




PostPosted: Thu Dec 28, 2006 12:25 pm   Post subject: (No subject)

Let me take it back to your main problem for a sec. these guys are right...you should be using Rand.Int....but, you obviously haven't learned it yet, or are having trouble with the concept. so screw it. Laughing use randint. be happy. Very Happy

as for seed appearing too close to one another, just have an if statement that determines wheather or not there are seed right by it. this can be done using whatdotcolor. if there is any black with a radius or 10, say, then don't draw one there, instead redraw it somewhere else. okay? easy stuff. Razz
gugiey




PostPosted: Thu Dec 28, 2006 11:02 pm   Post subject: (No subject)

Hackmaster wrote:
Let me take it back to your main problem for a sec. these guys are right...you should be using Rand.Int....but, you obviously haven't learned it yet, or are having trouble with the concept. so screw it. Laughing use randint. be happy. Very Happy

as for seed appearing too close to one another, just have an if statement that determines wheather or not there are seed right by it. this can be done using whatdotcolor. if there is any black with a radius or 10, say, then don't draw one there, instead redraw it somewhere else. okay? easy stuff. Razz


lol ive bin waiting for u to post rofl. thanks

btw add me on msn gugiey@hotmail.com
Clayton




PostPosted: Fri Dec 29, 2006 9:38 am   Post subject: (No subject)

Hackmaster wrote:

Let me take it back to your main problem for a sec. these guys are right...you should be using Rand.Int....but, you obviously haven't learned it yet, or are having trouble with the concept. so screw it.Laughing use randint. be happy. Very Happy


Quite simply, No. Just giving up is not going to help. I personally believe that this is the reason that so many highschool students fail/nearly fail their CompSci classes, is because of that kind of outlook. Just saying, "who cares about the basics, lets rush graphics" has a lot to do with it as well. You should understand why or why not to do something, just saying "Yeah this works, just do it" doesn't help anyone at all. The reason I say use Rand.Int() over randint() is because Rand.Int() is a function whereas randint() is a procedure. "Why does this matter" you ask? Because, functions compute a value and return it. Procedures are different in that they don't return any kind of value, they just change the environment around them. Using procedures to change the rest of the program is considered to be bad coding style, and should be avoided at all costs. Why you ask? Because you have no idea what is happening to your precious variable inside that procedure. With a function however, you know exactly what's going on. It computes a value, and you assign that value to your variable externally.

Conclusion: Whenever there comes a point that you could use a function or a procedure, use the function instead.
Prince Pwn




PostPosted: Fri Dec 29, 2006 4:22 pm   Post subject: (No subject)

code:

function DoubleFcn (number : int) : int % Function
    result number * 2 % The DoubleFcn's number is doubled
end DoubleFcn

procedure TripleProc (number : int) % Procedure
    put number * 3 % Puts the 'number' tripled on the screen
end TripleProc

put DoubleFcn (5) % Puts the result of DoubleFcn on the screen
TripleProc (7) % Does what's inside TripleProc
Hackmaster




PostPosted: Fri Dec 29, 2006 7:39 pm   Post subject: (No subject)

Freakman. (sigh).

I've tried to get this argument across before to people who push this stuff. I know that it's a better way to do this. fine. but what if someone doesn't know about procedures and functions yet? what if it isn't taught? I knowthat my school (which this guy happens to go to) doesn't teach about procs and functions until grade 11. it sucks, I know, but people who are interested learn. however, other people aren't interested, and thus just want a simple answer, without the technicality.

This, by the way, is why engineers and programmers rarely make good salesmen. we usually go WAY to technical on the innocent person who just wanted a yes or no answer... or something simple, anyhow.

that's all. I Know that Rand.Int() is a better way to do things, but that is getting quite finikity, and I think that one problem with some people on compsci is that they push techincality and extreme detail a bit much. now people like me, experienced coders who know what you are talking about, know what you are talking about. we understand this is a better way of doing this, and this, and blah. but in this case, simplicty is of the essence.

thanks for hearing my rant... Laughing
ericfourfour




PostPosted: Sat Dec 30, 2006 12:33 pm   Post subject: (No subject)

Hackmaster wrote:
what if someone doesn't know about procedures and functions yet? what if it isn't taught?

They better learn themselves. It is one of the most important concepts of programming and if you can't understand what functions or procedures are you will never succeed in learning more complicated concepts. There are tutorials on functions and procedure, so what is holding them back from learning it?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 22 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: