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.
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.
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!
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.
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.
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.
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...
Bookmarks