febb: (Default)
[personal profile] febb
Хотел пощупать Random class in .NET.
Написал программу, которая считает количество циклов,
приводящих к повторному случайному числу.
Если там только int 32bit представление,
то можно было бы увидеть зацикливание,
но там оказывается больше, хотя seed - int.




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CheckRandom
{
    class Program
    {
        static void TestRandomLoop(int seed)
        {
            Random rnd = new Random(seed);
            int n0 = rnd.Next();
            Console.WriteLine($"Seed: {seed}\t\tn0: {n0} ");
            long len = 0;
            for (;;)
            {
                ++len;
                int n = rnd.Next();
                if (n == n0)
                {
                    Console.WriteLine($"\t\tLength: {len}  ");
                    len = 0;
                    //break;
                }
                if(len % 100000000 == 0)
                    Console.Write($"\t\tLength: {len}   \r");

            }
        }

        static void Main(string[] args)
        {
            for(int s=0; ;++s)
                TestRandomLoop(s);
        }
    }
}


This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

febb: (Default)
febb

March 2022

S M T W T F S
  1 2 345
6 7 89 101112
13141516171819
20212223242526
2728293031  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Mar. 10th, 2026 04:50 am
Powered by Dreamwidth Studios