Talk:ACORN (random number generator)

Latest comment: 1 year ago by Fred Underscore in topic C++11 example code

COI

edit

Do any editors here have a wp:coi? Slatersteven (talk) 16:54, 6 April 2022 (UTC)Reply

@Slatersteven@Blah2 yes! after reading numerous COI and POV pages it appears that I may have potential or apparent COI. But I am NOT the developer of ACORN, and I am NOT paid for any of my numerous contributions to Wikipedia, where I always do my best to have a neutral and critical point of view.
  1. where should this discussion be continued - here or on my talk page or on the COI page as suggested by @A. C. Santacruz
  2. how do you suggest that I should proceed ? (I suppose you and other mathematically-minded editors will want to judge notability and neutrality).
    jw (talk) 19:50, 6 April 2022 (UTC)Reply

Requested move 1 July 2023

edit
The following is a closed discussion of a requested move. Please do not modify it. Subsequent comments should be made in a new section on the talk page. Editors desiring to contest the closing decision should consider a move review after discussing it on the closer's talk page. No further edits should be made to this discussion.

The result of the move request was: moved. (non-admin closure) {{replyto|SilverLocust}} (talk) 01:27, 8 July 2023 (UTC)Reply


ACORN (PRNG)ACORN (random number generator) – Disambiguators should be intelligible to the common reader, not jargon. * Pppery * it has begun... 00:04, 1 July 2023 (UTC)Reply


The discussion above is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.

C++11 example code

edit

Hello! I've wanted to to give this PRNG a try before, but the current example code is somewhat impenetrable. I ran it through chatgpt to get a C translation, which I then turned into a C++11 implementation. It looks like this (i have no idea how to format it on this page):

// State array of arbitrary size.

// The first element must be odd, the other elements can be randomly set.

std::array<uint64_t, 16> state {

0xE907505CB59C77D1, 0x8D6CA05F581DA875, 0x66F0C7ABEDA8D656, 0xEA0FF0093C2D3AB4,

0x48DE7C3E7FA5F645, 0xDF816A1E4941B30E, 0x28FF5C18C591C8B2, 0xD86AB519D00D93E1,

0x7D1A153C980DEA8A, 0xAFF20955CB3FFC46, 0xA63707C164CD19F4, 0x953458E388B9020C,

0xCFCA87EBA0626046, 0x1E9AF6B90B7EBF91, 0xE86BDCAAE59D8EDA, 0xD0B78E2AD9B6C63D,

};

uint32_t acorn_u32() {

// Update the current element by adding the previous element to it.

// Note: the first element is never updated.

   for(int x = 1; x < state.size(); ++x) {
       state[x] += state[x - 1];
   }

// Return the high bits of the last element of the array.

   return state.back() >> 32;

}

Does this seem fit for inclusion?


Notes:

Unlike the current example which generates 64 bits and turns it into a double precision float, this code simply generates 32 bits (should maybe be even less? see below).

Also, I'm pretty sure the float generation method used in the fortran example code (division by modulus) introduces bias and besides, it isn't strictly part of the PRNG so I left it out.

Something else that doesn't seem to be mentioned anywhere is that the lower bits are of poor quality. Returning the full 64-bit element quickly fails PractRand's tests. I wanted to make sure I didn't do anything wrong so I searched around and found these polish forum posts (used google translate to read): [1]. This person realized the same thing: casting the generated bits to a double float will discard some of the lower bits and mask the problem, but it's not exactly spelled out very clearly.

Now, the C++ example code outputs 32 bits and will actually fail PractRand pretty early as well... to avoid this, 128 bit elements could be used or the output could be smaller (24 bits seem fine but isn't a convenient size, so the next step is 16 bits). I'm not a fan of either really, but if we would like the example to not fail PractRand early I'd maybe go with 16 bit output as 128 bit integers aren't super common (I think?).

Quick aside... I think everyone already knows, but the article was clearly written by someone with vested interest, haha. Fred Underscore (talk) 09:07, 5 July 2023 (UTC)Reply

Hi @Fred Underscore, there are not any hard and fast rules on Wikipedia, yet, about LLM but you can see some of the gathering consensus about them at both WP:LLM and WP:ChatGPT. I, personally, am pretty against including ChatGPT or other automatically generated code examples on Wikipedia. If a read wants to see such things, they're free to generate it themselves using a current LLM. We should only include well-understood (by the editor who adds it) and known-correct code as much as possible. So if you want to find either an open source version with a compatible license or you feel like you could write your own that'd be an improvement, that'd be welcome. Skynxnex (talk) 20:05, 17 July 2023 (UTC)Reply
Maybe I was being unclear! I asked chatGPT to translate the code to C as the current code example is very hard to read. With the help of the C translation I could figure out what the FORTRAN code is doing and I then wrote my own C++ implementation.
My reason for doing this whole thing in the first place is that the description of how ACORN works on its website is rather hard to follow (unless you're a comp sci person maybe), and the current code example is also hard to follow - FORTRAN is not very common in this day and age, and compact code with variable names such as "IXV1" and "KORDEJ" is hard to dissect. Fred Underscore (talk) 21:27, 17 July 2023 (UTC)Reply
Ah yes, I think if you've written an implementation like that using ChatGPT output to help you understand the problem, that should be fine. This maybe would require me to just understand ACRON itself a bit more and is for my own edification, but why does the C++ code have an explicit array with preset values while the Fortran doesn't?
(As for formatting the code, you would probably want to wrap it in <syntaxhighlight lang="c++">...</syntaxhighlight> which would give:
// State array of arbitrary size. 
// The first element must be odd, the other elements can be randomly set. 
std::array<uint64_t, 16> state { 
	0xE907505CB59C77D1, 0x8D6CA05F581DA875,	0x66F0C7ABEDA8D656, 0xEA0FF0093C2D3AB4, 
	0x48DE7C3E7FA5F645, 0xDF816A1E4941B30E,	0x28FF5C18C591C8B2, 0xD86AB519D00D93E1, 
	0x7D1A153C980DEA8A, 0xAFF20955CB3FFC46,	0xA63707C164CD19F4, 0x953458E388B9020C, 
	0xCFCA87EBA0626046, 0x1E9AF6B90B7EBF91,	0xE86BDCAAE59D8EDA, 0xD0B78E2AD9B6C63D, 
}; 
uint32_t acorn_u32() { 
	// Update the current element by adding the previous element to it. 
	// Note: the first element is never updated.
   for(int x = 1; x < state.size(); ++x) {
       state[x] += state[x - 1];
   }

// Return the high bits of the last element of the array.

   return state.back() >> 32; 
}
Hope that helps some.) Skynxnex (talk) 18:47, 18 July 2023 (UTC)Reply
Your comment about submitting AI generated content is understandable! Maybe I shouldn't even have mentioned it since it didn't submit anything generated, I guess I just wanted to detail my process for some reason.
In any case, I already had an idea of what the number generator was supposed to do, I just wanted to go through the "official" code example to make sure I got it right.
"why does the C++ code have an explicit array with preset values while the Fortran doesn't?"
I just filled an array with some randomly generated values to use as an example. It definitely could be left blank instead, with the comment above it mentioning how to initialize it.
::::// State array of arbitrary size. 
::::// The first element must be odd, the other elements can be randomly set.  
::::std::array<uint64_t, 16> state {};
::::
One could go even further and change the array to a vector (and maybe an accompanying init function that sets the length and some initial values), as the size of the array could be just about anything. Fred Underscore (talk) 18:39, 19 July 2023 (UTC)Reply