Random PBP


Closed Thread
Results 1 to 15 of 15

Thread: Random PBP

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: Random PBP

    Quote Originally Posted by Darrel Taylor View Post
    PBP's RANDOM command is FAR from RANDOM.
    Makes good pink noise though ...

    But anywho ...
    Code:
        RANDOM   RandVar
        Result = RandVar ** 7 + 1
    This is an older post I searched because I need to generate a random number and saw you can do it with a word variable. Like this fella, I need a smaller number.

    I'm having a hard time grasping what is going on with Result = ** 7 + 1
    Huh ?

    Saw --
    ** Returns the high 16 bits of a 16-bit multiply result

    But even that isn't making sense to me.

    Has there been any updates to random where you can apply it to more than a word? -thanks

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Random PBP

    That line of code will scale the WORD sized Randvar variable (0 to 65535) to a value ranging from 1 to 7.

    Bascially it's the same as doing Result = Randvar * 7 / 65536 + 1

    /Henrik.

  3. #3
    Join Date
    Feb 2013
    Posts
    1,132


    Did you find this post helpful? Yes | No

    Default Re: Random PBP

    Use biased zener connected to ADC and sample the input

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,139


    Did you find this post helpful? Yes | No

    Default Re: Random PBP

    What would the range be? Near the bias?

    I think a running timer that user reads the current state maybe good enough, although sure not random since it is repeating with specific period. But the reading period is not specific or related to the timer period.

    Ioannis

  5. #5
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Random PBP

    Most of the newer PICs have Internal Temp Sensing through the ADC Module. The Temperature result would be a good source for Random Seed generation, as it will fluctuate quite a bit.

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. Random Numbers
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 18th December 2008, 08:47
  3. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  4. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30
  5. 6 random numbers limiting to 49 ?????
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th June 2005, 23:27

Members who have read this thread : 2

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