PDA

View Full Version : random generator with a limiter



kenpo
- 27th April 2007, 18:27
one of the basic things I'd love to see in pic basic, would be to say random(9) and then get a random number from 1-9, rather than saying random and getting anything from 1-65,000.

Melanie
- 27th April 2007, 18:54
There's a dozen or more ways to do this... here's one...

MyWord var Word
MyByte var Byte

Random MyWord
MyByte=(MyWord//9)+1

Result is a value 1 thru 9... Not exactly rocket science... and it also leaves MyWord intact as the seed for the next itteration of the Random function.

A lot of the 'wishes' on the wish-list are there because folks can't use the basic building blocks already provided by MeLabs to build more complex functions. In this instance just one extra line of code provided the function you require. What people don't realise is, if you integrated all that additional functionality into the commands, it would just bloat-out your final code. Now that's great if you're Intel and Microsoft, because once one party comes out with a faster processor, the other party ends up slowing it down with abysmal software, but when your resources are limited to start with (say a 256 byte PIC10F part), and your super-duper RANDOM command takes up 220 bytes of that, it becomes a bit of a bummer!

kenpo
- 27th April 2007, 19:06
no, you're right it's not rocket science, and thanks for posting the code example as it's great to now know this, at the same time though, the idea of basic is that it should be basic, I find alot of the time simply coding in C is more direct, I think this is still a perfectly valid wish list item, perhaps even more so now, yes you can do it with only 2 extra lines, but you shouldn't need too, in most coding languages you can limit the random function.

it's great to look at it from the standpoint of people using the compiler for years, but think more about it being used in highschools or colleges for the first time.

Melanie
- 27th April 2007, 19:17
Like I say, the core building blocks are all there. It's down to whether the user has the knowledge to string them all together to produce the desired result. It's when that knowledge (or call it experience or skill or whatever) doesn't exist, the call goes out for additional functionality in those core building blocks.

kenpo
- 27th April 2007, 19:56
I don't really agree that not having control over how a function functions doesn't matter because if you know the specific iteration of the language well you can just do something completely different to get the same result.

Melanie
- 27th April 2007, 20:13
I draw an analogy...

Imagine a real-life Art Class...

A whole bunch of students sitting around a naked model (insert specis/gender here of whatever turns you on)...

The Tutor hands out a sheet of paper and crayons to each student, and asks them to draw whatever part piques their interest...

The students all start to draw, but one unskilled beginner, rather than use the opportunity to hone their artistic skills instead asks the Tutor for a Digicam and a Printer...

So yes, you all get a result in the end. On the one hand you make the effort, on the other somebody/something else does it for you...

kenpo
- 27th April 2007, 20:23
I'm not going any further because we're never going to get anywhere, by your argument you and I should just go use assembly.
A better analogy would be that we're both using digital cameras (picbasic, not drawing-assembly) and I'm saying it would be great if it had a zoom lens, and you're saying "you should just walk instead, it's lazy to want a zoom".

mister_e
- 27th April 2007, 23:53
Seems it's easy to crank some people here... Agree or not, Melanie is true. Maybe you take it too serious and as a direct attack. Calm down a little bit and try to read between the lines.

If i wanted to flash an led 70 000 times... should i think really hard to find a solution knowing that a WORD variable can't hold that value, ask Melabs to create a DWORD sized variable only for me or change to another compiler/language?

Come on... unfortunately today's people want everything for yesterday without effort... it's worst now with forums... something my parents and myself haven't at school.

No coincidence why there's so many new compiler, so many microcontroller, so many dedicated ICs. Copy/paste.. yeah it works... i'm the king of the world. %&^%*%& it doesn't work, i will blame others :D

kenpo
- 28th April 2007, 00:44
I'm not taking it personally and I'm not upset. why is mentioning having control over a function would be nice causing you guys to leap and tell me to shush and go away?

Pic_User
- 28th April 2007, 02:38
Hi kenpo,

Your idea is the “PBP Wish List” category.
That's what a wish category should be used for!

Thank you, I like the idea.

-Adam-

Melanie
- 28th April 2007, 08:16
You can wish for whatever you want, hey I'm not stopping you.

The point I was trying to convey is that in many cases people have already got what they are wishing for, if only they stopped to learn what they've got (or read the manual as Skimask would point out) to realise the fact.

In post #1 of this thread you wanted a function, and got it in post #2 with a simple math statement. So if it's that easy, why bloat-out the core function with unnescessary code?

Your camera in this case already has the zoom facility... you've just not discovered how to use it yet. Rather than have an obvious button called Zoom, it's embedded several Menu levels deeper down and needs a better understanding of the camera to discover all it's features.

T.Jackson
- 28th April 2007, 11:07
I think I'll stay on neutral grounds with this one. Both Melanie & Kenpo have made some points that I agree with.

BASIC - Beginners All Purpose Symbolic Instruction Code - as its name suggests is a language primarily directed towards the beginner. However, because of its sheer ease-of-use and RAD nature Rapid-Application-Development, many professionals also continue to use it.

Traditionally, BASIC has always been a function orientated language. Much like buttons on a calculator, entire complex and length procedures are preserved behind simple syntax. (This is BASIC's strength)

It also has a very big weakness too. Not such a big deal with say Visual BASIC, because nowadays, you have what seems like an infinite amount of storage at your disposal. But when a lack of a few bytes can put an entire project on ice, you really don't want any protocol that's bloated.<br/>