random generator with a limiter


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    46

    Default random generator with a limiter

    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.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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!

  3. #3
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    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.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.

  5. #5
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    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.

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

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

Similar Threads

  1. Random Numbers
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 18th December 2008, 08:47
  2. 6 random numbers limiting to 49 ?????
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th June 2005, 23:27
  3. Random number results
    By bartman in forum mel PIC BASIC
    Replies: 3
    Last Post: - 9th March 2005, 17:39
  4. Random function - How to limit it ??
    By martarse in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 30th November 2004, 14:05
  5. more random number questions
    By bartman in forum mel PIC BASIC
    Replies: 1
    Last Post: - 14th November 2004, 17:55

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts