Resolved Falsification of probability

DANILIN

Active member
Joined
Oct 19, 2018
Messages
44
Programming Experience
10+
Falsification of probability

exploring possibility of falsification of random
qbasic qb64 programs were created in an hour
and a table using formulas

= CASEBETWEEN(0;1)
= IF (B3 = B2; C2 + 1; 0)
= COUNTIF (C$3: C$55000; D2)
= SUM(E2:E10)
= E2 / E3

randus012.png


idea: fake a 50% chance

results:

research E green pure excel:
randomly distributed naturally

research 0 yellow qb 0:
randomly distributed naturally

research 1 in red qb 1:
explicit fake equal number in a row

research 2 violet qb 2:
smart fake but not all programmed
and skew due to algorithm

Conclusion: identify fake random real

Visual Basic:
' 0.bas
OPEN "0.txt" FOR OUTPUT AS #1
FOR s = 1 TO 50000: PRINT #1, (INT(RND * 1000) MOD 2): NEXT
CLOSE
Visual Basic:
' 1.bas
OPEN "1.txt" FOR OUTPUT AS #1
FOR d = 1 TO 5: FOR s = 1 TO 100
FOR i = 1 TO s: PRINT #1, 1: NEXT
FOR i = 1 TO s: PRINT #1, 0: NEXT
NEXT: NEXT: CLOSE
Visual Basic:
' 2.bas
OPEN "2.txt" FOR OUTPUT AS #1
FOR k = 1 TO 100: FOR s = 1 TO 7
FOR d = 1 TO 2 ^ (7 - s)
FOR i = 1 TO s: PRINT #1, 1: NEXT
FOR i = 1 TO s: PRINT #1, 0: NEXT
NEXT: NEXT: NEXT: CLOSE

sequence fake shuffled
turns into a random sequence

and began to correspond to distributions

falsernd33.gif


and excel more clearly than programs
but c# synthesis programs are possible online


using a random synthesis program
and dividing into small 0 and large 1
synthesized 55000 random and tested

despite normality of number of consecutive 0...7
a larger number in a row is not possible
therefore sequence is worse than usual rnd

Visual Basic:
'rndxx.bas
OPEN "rndxxx.txt" FOR OUTPUT AS #1

FOR i = 1 TO 55555: r = Rand
IF r < 0.5 THEN PRINT #1, 0 ELSE PRINT #1, 1
'IF r <= 0.5 THEN PRINT #1, 0 ELSE PRINT #1, 1
'IF r <= 0.7 THEN PRINT #1, 0 ELSE PRINT #1, 1
NEXT: CLOSE

FUNCTION Rand: STATIC Seed
x1 = (Seed * 214013 + 2531011) MOD 2 ^ 24
Seed = x1: Rand = x1 / 2 ^ 24
END FUNCTION

rndxx.png


in C# randomness is also low-power
I suppose understood by people as supposedly normal

C#:
using System;using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace Rextester
{ public class Program
    { public static void Main(string[] args)
        { Random rand = new Random();
for (int i = 1; i < 5555; i++)
{ var d = rand.Next(2);
if (d<0.5)
    Console.WriteLine("0");
     else Console.WriteLine("1");
}}}}

on-line compiler: DANILIN probability, C# - rextester

significant reliable probability: shuffled
that is: 2-sided and that is: integraly probability

Program peretas.bas creates a sequence
random a: 0 and 1 by manual algorithm from Internet

and program creates random d: 0 ... 77777
for shuffling and sorting an array d array a is ordered
and perhaps against repetition it is better to shuffle cards 1000000

Visual Basic:
'peretas.bas
DIM a(55555), d(55555)

OPEN "aa.txt" FOR OUTPUT AS #1: OPEN "dd.txt" FOR OUTPUT AS #2
OPEN "aaaa.txt" FOR OUTPUT AS #3: OPEN "dddd.txt" FOR OUTPUT AS #4

FOR i = 1 TO 55555: r = Rand: a(i) = INT(r * 2): PRINT #1, a(i): NEXT
FOR i = 1 TO 55555: r = Rand: d(i) = INT(r * 77777): PRINT #2, d(i): NEXT

FOR i = 1 TO 55554: FOR j = i TO 55555
IF d(i) > d(j) THEN SWAP d(i), d(j): SWAP a(i), a(j)
NEXT: NEXT

FOR i = 1 TO 55555: PRINT #3, a(i): PRINT #4, d(i): NEXT
CLOSE

FUNCTION Rand
STATIC Seed
x1 = (Seed * 214013 + 2531011) MOD 2 ^ 24
Seed = x1
Rand = x1 / 2 ^ 24
END FUNCTION

Theoretical values in Excel Excel via formulas

=C3/2
=D3+C4
=D4*55000

show: out of 55000 for 7 steps covered 54570
numbers in their sequences
and probably deviation betrays a false accident

and shuffling involved 54885 close to theory

Theoretical values in Excel Excel via formulas



fldelen.gif
 
thank you for rushing me:
I have an archive today and everything will go into the archives

and earned almost from the 1st time
and suitable for learning c#
C#:
//tasov.cs
using System; using System.Linq;
using System.Collections.Generic;
using System.Text; using System.IO;
namespace tasov
{ class Program
    { static long[] a; static long[] d;
        static void Main(string[] args)
        {a = new long[55500]; d = new long[55500]; 
var inpFile = new StreamReader("aa.txt");
for (int i = 1; i <= 55000; i++) 
{ a[i] = Convert.ToInt64(inpFile.ReadLine());
d[55000-i+1] = a[i]; }

for (int i = 1; i <= 54999; i++) 
for (int j = i; j <= 55000; j++) 
if (d[i] > d[j])
{ var temp = d[i]; d[i] = d[j]; d[j] = temp;
temp = a[i]; a[i] = a[j]; a[j] = temp; }

var outFile = new StreamWriter("vv.txt");
for (int i = 1; i <= 55000; i++) 
outFile.WriteLine(a[i]);
Console.ReadKey();}}}

i compile through tasov.bat
C#:
csc /nologo tasov.cs
pause

checked: results are identical
 
Last edited:
Why are you doing a bubble sort with this:
C#:
for (int i = 1; i <= 54999; i++) 
for (int j = i; j <= 55000; j++) 
if (d[i] > d[j])
{ var temp = d[i]; d[i] = d[j]; d[j] = temp;
temp = a[i]; a[i] = a[j]; a[j] = temp; }
When you could just do:
C#:
Array.Sort(a);
Array.Reverse(a);
 
Or better yet, since post #16 said it was using LINQ, well then might as use LINQ to its fullest:
C#:
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace tasov
{
    class Program
    {
        static void Main()
        {
            var entries = Enumerable.Repeat(0, 55000)
                                    .Select(_ => int64.Parse(Console.ReadLine()))
                                    .OrderByDescending(e => e)
                                    .Select(v => v.ToString());
            File.WriteAllLines("vv.txt", entries);
        }
    }
}
 
I will study our programs on weak arrays but:
more carefully:

a = 15973
d = 37951 yes inverse

sorted d and dependent a
d = 13579
a = 31759

I'm testing the idea: RNG trigonometric

created a bad array that doesn't pass validation
binary even\odd and small\large

therefore, we shuffle equally real in Excel & basic & c#
just using this bad array

means: sequence is weak
shuffled through a sequence of weak
turns into a normal sequence

based on results of this topic

in attach arrays-d-a-v.zip: origin array aa.txt
and basic array dd.txt and basic array vv.txt
 

Attachments

  • arrays-d-a-v.zip
    146.5 KB · Views: 17
Last edited:
Oh I see. You were trying to rearrange the array a based on how d is sorted. Sorry I missed that.

But why even sort the numbers? I thought you were looking at just the distribution of the numbers. Distribution is not dependent on order.
 
Here's a re-write of post #17 with that new understanding of what you are trying to do:
C#:
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace tasov
{
    class Program
    {
        static void Main()
        {
            var dValues = Enumerable.Repeat(0, 55000)
                                    .Select(_ => Int64.Parse(Console.ReadLine()));
            var entries = dValues.Zip(dValues.Reverse(), (d, a) => new { D = d, A = a })
                                 .OrderBy(e => e.D)
                                 .Select(e => e.A.ToString());
            File.WriteAllLines("vv.txt", entries);
        }
    }
}
 
I'm testing idea: RNG trigonometric

created a bad array that doesn't pass validation
binary even\odd and small\large

therefore, we shuffle equally real in Excel & basic & c#
just using this bad array

means: sequence is weak
shuffled through a sequence of weak
turns into a normal sequence

based on results of this topic

my program implements equal for each: excel & basic & c#
but the program above is difficult for me
and still need to connect a ready array
for example, weak array aa.txt from the archive and must match dd.txt
 

Attachments

  • arrays-d-a-v.zip
    146.5 KB · Views: 15
So you are just doing two simple distribution tests:
Are there relatively the same count of odd and even numbers?
Do the numbers divide relatively evenly as high and low numbers?

So why are you doing all the extra steps to generate a text file, and then import into Excel, and then analyze in Excel. I thought you were doing a more extensive set of tests for randomness like in:
Dieharder: Robert G. Brown's General Tools Page
or
TestU01: Empirical Testing of Random Number Generators

If all you need are those two simple for tests for odd/even and high/low you could just implement it in C# and save yourself a lot of time: Here's a quick and dirty implementation I wrote:
C#:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace TestRandomness
{
    interface IRandomNumberGenerator
    {
        int Next();
    }

    class BuiltInCSharpRNG : IRandomNumberGenerator
    {
        Random _random = new Random();

        public int Next() => _random.Next();
    }

    class ReadPiDigitsFromFile : IRandomNumberGenerator
    {
        StreamReader _reader = new StreamReader("pi1000000.txt");

        public ReadPiDigitsFromFile()
        {
            // Skip the "3." at the beginning of the file
            _reader.Read();
            _reader.Read();
        }

        public int Next() => _reader.Read() - '0';
    }

    class GetUserInputRNG : IRandomNumberGenerator
    {
        public int Next()
        {
            while (true)
            {
                Console.Write("Enter a random number: ");
                if (int.TryParse(Console.ReadLine(), out int sample))
                    return sample;
                Console.Error.WriteLine("Cannot parse that number. Try again.");
            }
        }
    }

    class DanilinUserInputReorderRNG : IRandomNumberGenerator
    {
        IEnumerator<int> _enumerator;

        public DanilinUserInputReorderRNG(int count)
        {
            var dValues = Enumerable.Repeat(0, count)
                                    .Select(_ => int.Parse(Console.ReadLine()))
                                    .ToList();
            var aValues = new List<int>(dValues);
            aValues.Reverse();
            var samples = dValues.Zip(aValues, (d, a) => new { D = d, A = a })
                                 .OrderBy(e => e.D)
                                 .Select(e => e.A);
            _enumerator = samples.GetEnumerator();
        }

        public int Next()
        {
            if (!_enumerator.MoveNext())
                throw new InvalidOperationException("No more samples available.");
            return _enumerator.Current;
        }
    }

    class Program
    {
        void ShowPartitionDistribution(string leftLabel, string rightLabel,
                                       IEnumerable<int> samples,
                                       Func<int, bool> predicate)
        {
            int left = 0;
            int count = 0;
            foreach(var sample in samples)
            {
                ++count;
                if (predicate(sample))
                    left++;
            }
            int right = count - left;
            double leftPercentage = Math.Round((100.0 * left) / count, 5);
            double rightPercentage = 100.0 - leftPercentage;

            Console.WriteLine($"{leftLabel}/{rightLabel}: {left} ({leftPercentage}%) / {right} ({rightPercentage}%)");
        }

        bool IsOdd(int n)
            => n % 2 != 0;

        void ShowOddEvenDistribution(IEnumerable<int> samples)
            => ShowPartitionDistribution("Odd", "Even", samples, n => IsOdd(n));

        double GetMedian(IEnumerable<int> samples)
        {
            var sorted = samples.OrderBy(n => n).ToList();
            int count = sorted.Count();
            int mid = count / 2;

            return IsOdd(count) ? sorted[mid]
                                : ((long)sorted[mid] + (long)sorted[mid + 1]) / 2.0;
        }

        void ShowHighLowDistribution(IEnumerable<int> samples)
        {
            var median = GetMedian(samples);
            ShowPartitionDistribution("Low", "High", samples, n => n < median);
        }

        void ShowDistributions(string label, IRandomNumberGenerator generator, int count)
        {
            var samples = new List<int>();
            for (int i = 0; i < count; i++)
                samples.Add(generator.Next());

            Console.WriteLine($"{label} generator:");
            ShowOddEvenDistribution(samples);
            ShowHighLowDistribution(samples);
            Console.WriteLine();
        }

        void Run()
        {
            ShowDistributions("C#", new BuiltInCSharpRNG(), 55000);
            ShowDistributions("pi", new ReadPiDigitsFromFile(), 55000);
            ShowDistributions("user input", new GetUserInputRNG(), 5);
            ShowDistributions("danilin reorder", new DanilinUserInputReorderRNG(5), 5);
        }

        static void Main()
        {
            new Program().Run();
            Console.ReadKey();
        }
    }
}

For the GetUserInputRNG and DanilinUserInputReorderRNG, I only call them to get 5 inputs. You can obviously change that to be your test limit of 55000 if you wish to type in that many numbers.

Anyway, as I said earlier, the order shouldn't matter for your two distribution tests because it doesn't really matter if a number is even or even and it is first, second, third, etc.; nor does it matter if a number is high or low if it is first, second, third, etc. Yes, the order will matter if you had more sophisticated tests, but currently, you don't.

As an aside, I discovered a bug with my LINQ implementation of your input re-ordering. See the updated code in this post which instantiates 2 different lists first before zipping them together (see lines 54-61), instead of my previous post #21 where I tried to zip dValues and its reverse directly.
 
Checking in Wolframalpha

Reliability win and lose
both probability of winning and losing create 4 combinations:

C+p^N=1
(1-C)+p^N=1
C+(1-p)^N=1
(1-C)+(1-p)^N=1

Everything is interchangeable:

C=1-c
c=1-C
P=1-p
p=1-P

Artificial intelligence of Wolframalpha knows logarithm:

solve C+(1-p)^N=1 for N

solve C+(1-p)^N=1 for N - Wolfram|Alpha

wolframalpha.png
 
C+p^N=1
(1-C)+p^N=1
Huh?

That's not possible..
If both equations are equal to 1, then:
C+p^N=(1-C)+p^N
Subtract p^N from both sides:
C=(1-C)
C=1-C
Subtract C from both sides:
0=1-2C
which is clearly not true.
 
Last edited:
Big C & P: winning
Small c & p: losing

Original Excel formula:

=log(1-0,99)/log(1-0,25)
=16

So after 16 zeros in a row
for probability 0.25=25%=1/4
further reliability of 99% of one

So letters are big or small:

=log(1-C)/log(1-P)
=log(c)/log(p)
=log(0,01)/log(0,75)
=16

C+(1-P)^N=1
C+p^N=1
= 0,99 + 0,75^16 = 1
 
Quantum random observe principles of binomial distribution
 
Back
Top Bottom