Sorry

Discussions related to mathematics, numerical methods, graph plotting etc.
Post Reply
Patrick M
Posts: 78
Joined: Mon 02 Apr 2018, 21:51

Sorry

Post by Patrick M » Tue 01 May 2018, 00:11

Sorry. Please delete this thread.
Last edited by Patrick M on Tue 01 May 2018, 20:40, edited 2 times in total.
P.M.

guest
Posts: 150
Joined: Mon 02 Apr 2018, 09:12

Re: My own random number function

Post by guest » Tue 01 May 2018, 09:09

Patrick M wrote:
Tue 01 May 2018, 00:11
A few months ago I made my own random number generator, through trial and error.
Why? There are many 'standard' PRNGs to choose from, each based on sound mathematical principles, having known properties and evaluated using a thorough battery of tests. It's notoriously difficult to design a high-quality PRNG from scratch, so why even attempt it? There are sadly examples of such 'do it yourself' efforts having badly backfired, one being the PRNG in Liberty BASIC which is known to be biased and unusable for any serious applications.
It's probably not very good
What an admission! What are its basic properties that make it (potentially) better that the built-in RND? What is its sequence length? How have you confirmed that it really does achieve that sequence length, given that running it until it repeats would probably take too long? What other analyses of its performance have you carried out?

My advice to anybody, even highly skilled mathematicians, is never to write your own PRNG. Apart from the risk and difficulty of doing so, there really is no cause to when so many standard, trustworthy, algorithms, with any set of properties you might want, are available. You need only look as far as the BB4W Wiki for one of them, and there is another in the Assembler section.

Richard.

Patrick M
Posts: 78
Joined: Mon 02 Apr 2018, 21:51

.

Post by Patrick M » Tue 01 May 2018, 12:05

.
Last edited by Patrick M on Tue 01 May 2018, 20:39, edited 2 times in total.
P.M.

guest
Posts: 150
Joined: Mon 02 Apr 2018, 09:12

Re: My own random number function

Post by guest » Tue 01 May 2018, 13:54

Patrick M wrote:
Tue 01 May 2018, 12:05
I posted it here only because I noticed the other thread about RND, and started wondering if there might be a mathematician or someone on the forum who would have something interesting to say about it.
I'm not a mathematician but I can tell by inspection that it has a 'fatal' flaw. The code appears to be intended to return an integer in the range 0 to in%-1, but there is a finite chance that it will return the value in%! To me that makes it not simply "not very good" but broken, and I'm afraid a classic example of why you should not try to 'roll your own'. :shock:

Here's the proof:

Code: Select all

      PROCinitpmrand
      PRINT FNpmrand(10)
      END

      DEFPROCinitpmrand
      rand%=&A43C58DF
      ranb%=&C58D1487
      ENDPROC

      DEF FNpmrand(in%)
      SWAP rand%,ranb%
      rand%=rand%<<15 OR rand%>>>16
      rand%=(NOT rand%)<<1 OR (NOT rand%)>>>31
      rand%=rand% EOR ranb%>>>3
      rand%=rand%<<8 OR rand%>>>23
      =INT((rand% AND 2147483647)*(in%/2147483647))
Richard.

Patrick M
Posts: 78
Joined: Mon 02 Apr 2018, 21:51

.

Post by Patrick M » Tue 01 May 2018, 18:23

.
Last edited by Patrick M on Tue 01 May 2018, 20:39, edited 1 time in total.
P.M.

guest
Posts: 150
Joined: Mon 02 Apr 2018, 09:12

Re: My own random number function

Post by guest » Tue 01 May 2018, 19:54

Patrick M wrote:
Tue 01 May 2018, 18:23
It's identical except for the last line.
So any other weaknesses it might (and almost certainly does) have will be unaffected. You clearly are not going to take my advice, so I'll stop giving it. I might as well kill myself, for all the notice anybody takes of my opinion. In fact I think I will.

Richard.

Patrick M
Posts: 78
Joined: Mon 02 Apr 2018, 21:51

Sorry

Post by Patrick M » Tue 01 May 2018, 20:13

Sorry, I didn't understand that you felt so strongly about it. I will of course only use proper random number functions where it really matters. Actually, also where it doesn't matter, because I would probably still want to avoid whatever strange bugs or problems could result.

I think the situation here is a misunderstanding from both of us. I didn't realise you were giving very serious advice, and you may not have understood that my attitude towards this particular thing was entirely not serious. As I said, it was a bit of fun.
I'm sorry for upsetting you.

Edit: I would also like to be clear that I respect you and value your opinion, BB4W/BBCSDL is an absolutely fantastic thing, thanks for developing it and making it readily available to everyone.

Edit 2:
Please don't kill yourself. I can tell that you're probably going through a really hard time right now. I don't know what to say, but I can at least apologise for bothering you and wasting your time with this silly thread.

I want to reiterate that I have enormous respect and admiration for you and your work. In March I bought BB4W almost entirely as a gesture of support - I use linux exclusively, the only windows system I have is a decade old laptop with XP.
Last month I spent a full week writing programs with BBCSDL, I had a great time with it. Your BASIC has had a positive influence on the lives of several people and there are in fact many people who regard you very highly.

I apologise again for wasting your time, and I'd also like to say thanks for answering my questions about BB4W/BBCSDL.

I wish you well.
PM
P.M.

Post Reply