Computer Science Canada

help with randint

Author:  gugiey [ 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

Author:  Clayton [ Sat Dec 23, 2006 11:22 am ]
Post 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?

Author:  gugiey [ Wed Dec 27, 2006 8:24 pm ]
Post subject:  huh

huh

Author:  Ultrahex [ Wed Dec 27, 2006 9:31 pm ]
Post subject: 

minute, what does huh mean?

Author:  Clayton [ Wed Dec 27, 2006 9:33 pm ]
Post 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)

Author:  Ultrahex [ Wed Dec 27, 2006 9:34 pm ]
Post 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?

Author:  gugiey [ Wed Dec 27, 2006 11:08 pm ]
Post 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

Author:  [Gandalf] [ Wed Dec 27, 2006 11:45 pm ]
Post 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

Author:  gugiey [ Wed Dec 27, 2006 11:47 pm ]
Post 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

Author:  Hackmaster [ Thu Dec 28, 2006 12:25 pm ]
Post 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

Author:  gugiey [ Thu Dec 28, 2006 11:02 pm ]
Post 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

Author:  Clayton [ Fri Dec 29, 2006 9:38 am ]
Post 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.

Author:  Prince Pwn [ Fri Dec 29, 2006 4:22 pm ]
Post 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

Author:  Hackmaster [ Fri Dec 29, 2006 7:39 pm ]
Post 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

Author:  ericfourfour [ Sat Dec 30, 2006 12:33 pm ]
Post 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?

Author:  Hackmaster [ Sat Dec 30, 2006 8:32 pm ]
Post subject: 

experience.

What is holding people back is the experience factor. what if they just started a month ago? or even 2 months? what if they just want a non complicated answer? Eric, (and anyone else) should check out my post in general discussion. it's titled "What is Compsci.ca?" and it deals with this issue. after you have read that, then we'll have this discussion.

Author:  ericfourfour [ Sun Dec 31, 2006 12:11 am ]
Post subject: 

Hackmaster, I read your post and I see where you are coming from. I however, see this kind of issue this way.

I believe you have mentioned that you have programmed in C before. When dealing with that language what did you learn first, functions or how to get a random number? Obviously, you learned functions first. You probably learned functions before most of the other concepts. Getting a random number just is not important in the early stages of programming.

The problem here is that students are not being taught the basics and this is bringing them into issues that would have never come up if they took the time to learn the fundamental concepts. This can partly be their teachers fault, but it is their responsibility to learn the essentials if they were never taught. This means asking a teacher, going on compsci.ca, asking peers, etc.

Author:  Hackmaster [ Sun Dec 31, 2006 10:24 am ]
Post subject: 

that's not quite right....


if you go to the bookstore and buy any coding book titled " (insert language here) for dummies", they will almost always teach you randomization before functions. I know the C one does. I know that I was taught turing that way. and I agree that it isn't the best way to do things. however it does offer something that the early coder needs:

instant gratification.

an earlier programmer will definatly want to know how to choose a number between 1 and 10 before he wants to learn about functions.

and that's the other thing.

there are 5 basic stages to programming.

1: Basic: knows essentially nothing.
2: Functions: knows about functions and how to use them
3: general familiarity: begins to understand that coding is transferable and not only done in one langauge
4: objects: learns the concept of object oriented code.
5: L337: knows about essentially everything in one langauge, and probably a lot in several more, as well.


someone who just started won't want to know about functions. each one of these states is a big milestone, and it takes a whole new way of thinking to get around it.

Author:  Prince Pwn [ Sun Dec 31, 2006 1:31 pm ]
Post subject: 

Quote:

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.


I agree with you fully. Some people on these forums simply wont understand (probably for the rest of their lives) that people take up programming as an additional credit, and have many difficulties their first year. Just telling them to learn all this extra stuff will not help them in the end, but confuse them more. There are simpler ways in helping students that don't involve all these confusing terms us geeks use.

*sorry for deleting my original post for those who were about to read it*

Author:  CodeMonkey2000 [ Sun Dec 31, 2006 3:27 pm ]
Post subject: 

This has gotten off topic. I think it's time to lock it.

Author:  Hackmaster [ Mon Jan 01, 2007 8:41 pm ]
Post subject: 

ok, well, before it does get locked, anyone who is interested in this subject and have comments, go to general discussion and post under "What is compsci.ca?" It has this debate in it. there seems to be lots of interest in this, so let's keep it up!

Author:  Cervantes [ Mon Jan 01, 2007 8:53 pm ]
Post subject: 

spearmonkey2000 wrote:
This has gotten off topic. I think it's time to lock it.

I don't know how to say this without sounding snappy, but: Thank you, but if we needed your opinion on this issue, you'd be a mod.

Sorry, I know that sounded really snappy. I just couldn't find a way to tone it down. My apologies.

Anyways, I'm not going to lock this thread, because it's a good discussion. If you guys want to move it over to [GD], that's fine. (Just, please try to keep the discussion in one place--not raging on two fronts.) I just wish I could merge threads; but alas, that's for V3.


: