random number in Edata - Page 2


Today 19:02
Forum: The Lounge
Starter: towlerg
Views: 0
Replies: 1
Today 10:40
Forum: Proton Studio
Starter: Puffeltje
Views: 0
Replies: 13
Today 10:36
Forum: Proton Studio
Starter: wirecut
Views: 0
Replies: 1
+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: random number in Edata62 days old

  1. #11
    Member amateurtje's Avatar
    Join Date
    Aug 2008
    Posts
    114
    Thumbs Up
    Received: 6
    Given: 2
    Total Downloaded
    97.60 MB

    1 Not allowed!

    Default Re: random number in Edata

    I was re-reading my post and this sounded very negative (I am dutch but that was probably already clear). Anybody must be (of course) everybody...

    Quote Originally Posted by amateurtje View Post

    Thanks for anybody's reaction and helping me. It actually does something really small in the program but cost me about half a day or more...

    thanks all

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #12
    Junior Member wirecut's Avatar
    Join Date
    Nov 2018
    Posts
    73
    Thumbs Up
    Received: 0
    Given: 5
    Total Downloaded
    497.10 MB

    0 Not allowed!

    Default Re: random number in Edata

    This is the classic generator used by many languages, since the times of Fortran and Pascal.

    It generates 32-bit random numbers and turns them into Float numbers in the range from 0 to 0.99999999.

    If all you need is integer numbers, you could eliminate the Float part and save some memory.

    An additional option used in many languages is to initialize the "seed" with a value taken from a timer or ADC so that each time the sequence starts from a different number. If you need, you could do it easily by initializing the RndInt variable on power-up with the value taken from an ADC.

    Before to post the code I have adapted it to Proton Basic, and tested on a 12F1572 with compiler version 3.7.1.8

    Code:
    ' =================================================
    '  RANDOM GENERATOR
    ' =================================================
    Dim RndInt As Dword
    Dim RndFloat As Float
    
    Sub Update_Rnd()
        ' --------------------------------- generate a new Int32 random number 
        If RndInt = 0 Then RndInt = 1
        If (RndInt & 0x800000) <> 0 Then
            RndInt = (RndInt << 1) ^ 0x1D872B41
        Else
            RndInt = RndInt << 1
        End If
        ' --------------------------------- convert the new RndInt to RndFloat
        RndFloat = RndInt 
        RndFloat = RndFloat * 0.0000000002328306437
    EndSub
    
    ' =================================================
    '  Main Loop (used to test the random numbers)
    ' =================================================
    Main:
    Do    
        Update_Rnd
        HRSOutLn Dec RndInt, "  ", Dec8 RndFloat
        HRSOutLn ""
        DelayMS 1000
    Loop
    Last edited by wirecut; 12th June 2019 at 17:50.

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #13
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,225
    Thumbs Up
    Received: 371
    Given: 131
    Total Downloaded
    1.58 GB

    0 Not allowed!

    Default Re: random number in Edata

    Therre is another simpler way, but it will require a program written on teh PC that adds a random number to the HEX file before it is programmed.

    Thie could be a PC app that reads the HEX file, alters it with the random numbers, saves it back, overwriting the original, then calls the programmer. The eeprom data in a HEX file is very easy to find, but it will also need to have its CRC value altered based upon the random number placed in the HEX file.

    This would make the whole process invisible to a user.

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #14
    Junior Member wirecut's Avatar
    Join Date
    Nov 2018
    Posts
    73
    Thumbs Up
    Received: 0
    Given: 5
    Total Downloaded
    497.10 MB

    0 Not allowed!

    Default Re: random number in Edata

    My previous post is pretty useless, I just found out that the Proton already contains the Random function.
    And what I wrote does the same functions as the Proton Random.


    Reading this code can only be useful to understand how random numbers are made.

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. [SOLVED !] Need help with scaling a random number.
    By BillR in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 26th November 2015, 12:54
  2. Need a random number set
    By glenlivet in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 22nd August 2011, 18:13
  3. Any "better" random number gens out there?
    By picyerknows in forum Proton Plus Compiler v3
    Replies: 13
    Last Post: 22nd March 2008, 12:16
  4. Random number
    By all77 in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 26th October 2007, 02:45
  5. Random number
    By Roshan in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 30th April 2005, 16:34

Posting Permissions

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