Hi i have a good test for random numbers

For everything that's not in any way related to PureBasic. General chat etc...
dan yalte
User
User
Posts: 47
Joined: Thu Aug 13, 2015 8:56 am

Hi i have a good test for random numbers

Post by dan yalte »

Hi i have a good test for random number generators and as such i will be able to tell you all a whole lot about the numbers generated by PureBasic. when i am done.

I am working on a blackjack game that is both a game and a simulator. As such when using it as a simulator if i set the house rules to the ones i use local to me i know that in the end the house should show a 1.47% advantage over the player. I know if my sample size is good and the random numbers generated are good that should be the result.

Cool thing is it should be the same for all 7 seats. with a small change here and there, Less then 1 percent different over all. Will Pure Basic pass the test. I do not know yet. Will not know until i run the program with both Random Number routines. If not i have a good set i know are good.

Does Anyone care, the point here is We have a chance to test and maybe improve PureBasic in a good way. Most Random routines used even now in this day and age are considered to be weak. Also such routines are easy to do in C and Assembler.

Did the Dev guys do there homework here lets find out. Any idea's
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Hi i have a good test for random numbers

Post by BarryG »

dan yalte wrote:Did the Dev guys do there homework
Yes, as seen in the Help file for Random(), CryptRandom(), and OpenCryptRandom(). For your Blackjack purposes, you'd want to use OpenCryptRandom() with CryptRandom(), as then you'll get random numbers based on the OS's random number generator. So if the numbers are not "random" enough, you have to blame the OS and not PureBasic.
Help file wrote:The source for the random data is the "/dev/urandom" device on Linux or Mac OSX and the "Microsoft Cryptography API" on Windows.
dan yalte
User
User
Posts: 47
Joined: Thu Aug 13, 2015 8:56 am

Re: Hi i have a good test for random numbers

Post by dan yalte »

No body is blaming Purebasic For anything, Most Random Number generators are not done at the OS level. But are done in what is called user space or the user program level. Pc's do have an RND available at the OS level as most modern CPU's have a math co-possessor built in. But it is considered weak by modern Standards.

In 1988 i read article where a guy with a masters degree in math looked at how good most computers were at producing Random numbers back then. Pc's with no-coprocessor were at the bottom. pc's with a coprocessor were better but not as much as you might think.

Back then most people thought Hardware would win out all the time over software not the case.
turned out the best software RND's he found were the software ones being used by the 6800's series of CPU's. In fact they were way better then anything on any PC.

As i said before most RND's being used today are considered Weak. but not all. I will try both in Pure Basic for sure. Interesting to see what happens.

One RND i know is considered good is the one found in Microsoft Visual C++. been the same one since ver 4 i think.

Turns out there is a very specific way it is used in the game freecell. not the way you might think not just seeding the RND. With the game number and away you go.

Also turns out Nobody has done a good freecell for linux YET. people want to be able to play the same game number no matter what system they are on i will do that soon. LATER... ideas
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Hi i have a good test for random numbers

Post by Josh »

And what does this have to do with 'Feature Requests and Wishlists'? What is the wish to the Pb-Team?
sorry for my bad english
User avatar
NicTheQuick
Addict
Addict
Posts: 1223
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Hi i have a good test for random numbers

Post by NicTheQuick »

Purely software based random number generators are always weak. Only the cryptographic secure RNGs implemented by the operating system are considered really random. But because it requires some time to get a high entropy in the random bits pool you want to use cryptographic RNGs together with deterministic RNGs. Without the cryptographical secure RNGs every SSL session or any other cipher would be weak by definition.

There will nobody to blame. You will not find any weaknesses inside the CryptRandom* functionality of Purebasic.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Bitblazer
Enthusiast
Enthusiast
Posts: 732
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: Hi i have a good test for random numbers

Post by Bitblazer »

https://en.wikipedia.org/wiki/Random_number_generation

For example https://www.random.org/sequences/

If you are seriously interested, write a module which uses one of these services. But if you are really serious (for example because you want to use it for encryption), you wouldnt use any method which is delivered by a website as the data or the website could be manipulated at some unexpected point in time.
webpage - discord chat links -> purebasic GPT4All
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Hi i have a good test for random numbers

Post by BarryG »

dan yalte wrote:No body is blaming Purebasic for anything
Really? You did say the following:
dan yalte wrote:Will Pure Basic pass the test
dan yalte wrote:Did the Dev guys do there homework
This indicates PureBasic (and the team behind it) would hold the blame for any lack of true randomness.
dan yalte
User
User
Posts: 47
Joined: Thu Aug 13, 2015 8:56 am

Re: Hi i have a good test for random numbers

Post by dan yalte »

I think you missed my point. At some point along the Development of pure basic like anything else you implement things at some point as best you can and proceed on ward. at some point if you release something for use. You try to improve it over time like all software.

AS i tried to point out there are tons of RND routines out in the wild most lean toward being weak. In such cases it has nothing to do with the language you use.

In this case there are two different ways built into Pure Basic. And as such it will be cool to see how both compare to others.

I know what i should get for a base line. And as such there will need to be a group of tests in total to make sure that #1 the numbers are fairly random. Note in reality there is no real random numbers in software. it's a long explanation. #2 I also need to make sure that the sample size is large enough and that the DATA in this case the shuffled cards are not Biased in any way do to bad logic in terms of how the data is handled.

I have worked on this a long time so i know the subject well...

I may find that the routines built into Pure basic Are very good. I will know a whole lot more when i am done. One step at a time. Maybe i find a better way. MAYBE NOT.

As for feature request i was trying to suggest that if i found a better way to do random numbers maybe a change could be made. May not need to at all, Sorry i did not point it out sooner.

Getting there, do to all the rule variations it will take some time...
Last edited by dan yalte on Tue Jun 04, 2019 8:00 am, edited 1 time in total.
dan yalte
User
User
Posts: 47
Joined: Thu Aug 13, 2015 8:56 am

Re: Hi i have a good test for random numbers

Post by dan yalte »

I should have pointed out that if i find a better way to do Random numbers then what is built
into Pure Basic that perhaps changes could be made. I also understand for that to happen there would need to be a clear choice as for something better MAY NOT HAPPEN TIME will tell.

that is how it fits into a feature request. Sorry i did not point that out sooner.

It will be interesting to see what happens...
dan yalte
User
User
Posts: 47
Joined: Thu Aug 13, 2015 8:56 am

Re: Hi i have a good test for random numbers

Post by dan yalte »

Josh wrote:And what does this have to do with 'Feature Requests and Wishlists'? What is the wish to the Pb-Team?


Sorry i just pointed out in what way. The idea was to see how the routines in pure basic fair over all and if a better way can be found maybe a change can be made. Time will tell. see me other post sorry i did not emplane my point better.
dan yalte
User
User
Posts: 47
Joined: Thu Aug 13, 2015 8:56 am

Re: Hi i have a good test for random numbers

Post by dan yalte »

NicTheQuick wrote:Purely software based random number generators are always weak. Only the cryptographic secure RNGs implemented by the operating system are considered really random. But because it requires some time to get a high entropy in the random bits pool you want to use cryptographic RNGs together with deterministic RNGs. Without the cryptographical secure RNGs every SSL session or any other cipher would be weak by definition.

There will nobody to blame. You will not find any weaknesses inside the CryptRandom* functionality of Purebasic.

Well the hardware has come a long way for sure and most but not all software is weak. 85 to 90%
are weak. But when you get into legal matters they have very high standards for such things now
in order to try and protect data. Things do change over 30 years or so...
User avatar
NicTheQuick
Addict
Addict
Posts: 1223
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Hi i have a good test for random numbers

Post by NicTheQuick »

dan yalte wrote:
NicTheQuick wrote:Purely software based random number generators are always weak. Only the cryptographic secure RNGs implemented by the operating system are considered really random. But because it requires some time to get a high entropy in the random bits pool you want to use cryptographic RNGs together with deterministic RNGs. Without the cryptographical secure RNGs every SSL session or any other cipher would be weak by definition.

There will nobody to blame. You will not find any weaknesses inside the CryptRandom* functionality of Purebasic.

Well the hardware has come a long way for sure and most but not all software is weak. 85 to 90%
are weak. But when you get into legal matters they have very high standards for such things now
in order to try and protect data. Things do change over 30 years or so...
What do you want to even say with that? :D The RNG of Purebasic is exactly the same as the RNG of your operating system. You can be sure that these values are truly random.

Also there is this link: https://www.quora.com/How-can-one-tell- ... uly-random

You can not check for randomness.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
dan yalte
User
User
Posts: 47
Joined: Thu Aug 13, 2015 8:56 am

Re: Hi i have a good test for random numbers

Post by dan yalte »

Well there may not be true random numbers in software. if you are close to being random there are in fact a few things you can do to test how good an RND routine is.

#1 You can run a simulation of odds and compare it's results to real world results that are known. There will be some variance but if your sample size is good and your data is good it should be very close. Very small difference.

look at the Law of Probability.

You can look at the distribution of the numbers generated to see how long the routine goes before getting a repeating series of numbers. This is referred too as the bell curve. As there is not true randomness in software it will happen at some point. The longer it takes the better.

So in FACT you can test how good RND routines are. As for the link you posted that is getting to be very abstract. There are things being done with Quantum mechanical states. Where just trying to look at something will in fact change it's outcome. If they ever prefect such things we will have truly unbreakable encryption.

So in fact you can check for Randomness.

As for RNG in operating systems. Most operating systems don't have there own or use software.
some good. many are in fact bad about 75 to 85%. The PC does have routines in The Math Co-processor. These are considered to be weak. newer better ways are know. In both software and hardware. not all software ones are weak. many are but not all.

Some modern CPU's may have other such routines deep inside the CPU. such routines Are not likely Available to a user program.

My point is this when i am done i will have a very good way to test how good a number of such RND routines are including the two found in pure basic. I think one will be weak and the other fairly strong. Do not know yet. when i do i will show all what i have found.

This does not change what Pure Basic is, A very good programming tool. If i find a weakness in the RND routines inside Pure Basic The world will not end. If and only if i find such a weakness
can we ask for a change.

Such a change should not be done unless there is a clearly a better choice.

If i tell a simulator to deal say 7 million hands of blackjack and show the true odds based on the simulation. if they are very close to real world results. then i know the RND routines being used are good. should be done many times to check.

I know in my case if the rules used are set to the rules used local to me. i know the house should have a 1.47% advantage over the players.

Lets not get into the difference between Advantage and Percentage.closely related to each other
but very different.

Seems to me we should all want to see what the result is. If a better way is found can we not all gain from that. MAYBE?
User avatar
NicTheQuick
Addict
Addict
Posts: 1223
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Hi i have a good test for random numbers

Post by NicTheQuick »

dan yalte wrote:You can look at the distribution of the numbers generated to see how long the routine goes before getting a repeating series of numbers. This is referred too as the bell curve. As there is not true randomness in software it will happen at some point. The longer it takes the better.
This will happen with normal Random() function because it is a pseudo random generator. But you will not find any repetitions in the CryptRandom function.

Here you can read about the CryptRandom() function which derives on Linux from /dev/random: git.kernel.org/../random.c:52
You can also find a lot of information on Wikipedia: /dev/random

On Windows there is a similar approach, but have to google for it by yourself.

The good thing about randomness is that you can not measure it if it is perfectly random because you would need an indefinite amount of samples to do so.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Hi i have a good test for random numbers

Post by freak »

dan yalte wrote:You can look at the distribution of the numbers generated to see how long the routine goes before getting a repeating series of numbers. This is referred too as the bell curve. As there is not true randomness in software it will happen at some point. The longer it takes the better.
I think you are confusing things. What you are talking about is called "cycle length". The bell curve relates to the distribution of numbers, not when they repeat.

You talk a lot about results but don't have anything to show. Why not just wait and show your results when (if ever) you actually have some?

If you search around the forum you will see that the implementation of Random() has been discussed before and I even pointed to the paper on which the implementation is based. Feel free to read through it. I also recommend you read up on testing methods for pseudorandomnumber generators, there is a lot of research in that area (hint: the method you describe in your first post is not a good test for a number generator). If you find holes in the generator and can prove it, I am sure the original paper author will be interested in that as well.

Paper: http://www.agner.org/random/theory/chaosran.pdf
Original thread: viewtopic.php?p=288321#p288321

As pointed out by others, CryptRandom() is a completely different beast. Since this generator is periodically re-seeded from external sources (such as user input), you will not get a detectable cycle-length there ever. The implementations for such generators in the operating-systems are built on years of solid research, so good luck trying to poke holes into that one ;)
quidquid Latine dictum sit altum videtur
Post Reply