6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 9:42 am

All times are UTC




Post new topic Reply to topic  [ 245 posts ]  Go to page Previous  1 ... 13, 14, 15, 16, 17
Author Message
PostPosted: Sat Jun 24, 2023 10:40 am 
Offline
User avatar

Joined: Tue Nov 16, 2010 8:00 am
Posts: 2353
Location: Gouda, The Netherlands
Alex1 wrote:
When I announce a period for my algorithms, they remain random throughout the period. You have to do the same otherwise it's cheating for the challenge :lol: I too can create an algorithm with a period of 2^1024 but which will only be random on 100 KB :

It's not cheating. It's just a different category. I mention both the period as well as the PractRand results. The minimum period is important if you want to be sure to avoid bad seeds where the period is really short. For instance, if you initialize an LFSR with all-zero value, it gets stuck there, which is highly undesirable. When I say that the period is guaranteed to be 2^48, it means you don't have to worry about any bad seeds. As far as random quality is concerned, most 6502 users would happily pick a decent algorithm that's smaller & faster over one that's super high quality. When PractRand says it's good until 1 GB, it doesn't mean that it suddenly gets really bad. It just means that it's getting enough data that subtle patterns start to emerge. If you toss a coin that's heads for 50.00001% of the time, and you throw it billions of times, you start to realize that the coin is bad, but that doesn't mean it's useless. There are many applications where such a coin would be perfectly acceptable.

Quote:
I let my Raspberry PI (only one core used) run for 70 days to prove that my LFSR64 + LCG64 passed the 16 TB

That's fine if you only want to test one particular algorithm. If I'm trying to optimize for cycles, I run hundreds of different trials, sometimes thousands. I can't run hundreds of variations if each attempt takes weeks to run.

Quote:
1TB seems to me very little to prove that an algorithm is random

1TB for a 6502 system is exceptionally good.

Quote:
Time is not an issue, just use a system that can stay on for a long time because it does something else in the meantime.

It's an issue for me, because having the test running on my PC slows it down for other things, including other random generators that I'm testing.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jun 24, 2023 11:30 am 
Offline

Joined: Mon Mar 13, 2023 9:38 pm
Posts: 80
All you have to do is test your final generator, the one you propose as the best. For example, I proposed only two algorithms: LFSR64+LCG64 and ACR4. Not all intermediate test algorithms need to be tested for as long, only the last one should be.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jun 24, 2023 11:33 am 
Offline
User avatar

Joined: Tue Nov 16, 2010 8:00 am
Posts: 2353
Location: Gouda, The Netherlands
Off topic, but may be interesting to some. I've (finally) released a version of a pseudo random generator for Microchip AVR / Arduino.


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 25, 2023 3:49 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
Arlet wrote:
If you just wanted something super simple that produces every single 16 bit value exactly once, in random order, you could use something like this. 16 bit output in A,X:
Code:
    CLC
    LDA #1 ; any odd value
    ADC s+0
    STA s+0
    ADC s+1
    STA s+1
    ASL A
    ADC s+0
    TAX
    EOR s+0
    RTS

Good enough for games where you need a random action for a monster, but it's not going to pass any randomness tests.

Arlet, superficially, this looks very promising with an immediate of #39:

Attachment:
lfsr.PNG
lfsr.PNG [ 26.32 KiB | Viewed 4337 times ]


I wondered what the ASL was doing to help, and TBH it looks pretty good without it:

Attachment:
lfsr2.PNG
lfsr2.PNG [ 26.43 KiB | Viewed 4337 times ]


These images are of an Apple ][ hi-res screen after filling the screen approximately 30% full of "random" dots. The one without the ASL seems to have a slightly coarser "texture", but I think either one suits my purposes just fine. Do you (or anyone else) have any further comments before I add it to VTLC02? It's going to have a net cost of nine bytes, but I think the improved quality and slightly improved performance outweigh the cost.

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 26, 2023 4:04 am 
Offline
User avatar

Joined: Tue Nov 16, 2010 8:00 am
Posts: 2353
Location: Gouda, The Netherlands
The ASL is used to clear the carry flag, so that the output function is bijective (invertible). The first part of the code
Code:
CLC
LDA #1 ; any odd value
ADC s+0
STA s+0
ADC s+1
STA s+1

has a cycle length of 65536, going through each 16 bit value exactly once before repeating. However, the random quality is poor, so this is followed by an output function to make it more random. In order to keep the property that each value appears exactly once, this extra output function must be invertible. Now, an EOR operation is invertible, if you know one of the operands, however, an ADC is only invertible if you also know the carry state before the ADC. Since the code above leaves the carry in a random state, we need to define it. That's what the ASL does, in a tricky way.

ASL followed by ADC #0 performs an 8 bit rotate left of the accumulator, and clears the carry. The rotate left is invertible, and helps with the randomness. In the code, there's no ADC #0, but ADC s+0, which does the same thing as ADC #0, but also adds s+0 as a bonus.

If you remove the ASL, there will be 256 values that appear twice in the 65536 cycle period, and 256 other values that don't appear at all.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 245 posts ]  Go to page Previous  1 ... 13, 14, 15, 16, 17

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: