True Random PRO - Real randomness for Unity

True Random

Why use True Random?
“True Random” can generate random numbers for you or your game. They are “truly random”, because they are generated with atmospheric noise, which supersedes the pseudo-random number algorithms typically use in computer programs.

People use True Random for holding drawings, lotteries and sweepstakes, to drive online games, for scientific applications and for art and music.

Here some more information regarding “true” vs. “pseudo-” random:

There are two principal methods used to generate random numbers. The first method measures some physical phenomenon that is expected to be random and then compensates for possible biases in the measurement process. Example sources include measuring atmospheric noise, thermal noise, and other external electromagnetic and quantum phenomena. For example, cosmic background radiation or radioactive decay as measured over short timescales represent sources of natural entropy.

The second method uses computational algorithms that can produce long sequences of apparently random results, which are in fact completely determined by a shorter initial value, known as a seed value or key. As a result, the entire seemingly random sequence can be reproduced if the seed value is known. This type of random number generator is often called a pseudorandom number generator. This type of generator typically does not rely on sources of naturally occurring entropy, though it may be periodically seeded by natural sources. This generator type is non-blocking, so they are not rate-limited by an external event, making large bulk reads a possibility.

https://en.wikipedia.org/wiki/Random_number_generation#.22True.22_vs._pseudo-random_numbers

How does this differ from Unity Random?
Perhaps you have wondered how Unity generates randomness. In reality, random numbers used in Unity are pseudo-random, which means they are generated in a predictable fashion using a mathematical formula.

This is fine for many purposes, but it may not be random in the way you expect it to be when you think of dice rolls and lottery drawings.

2966280--621685--Random.png

Features:
Generate true random

  • Following data types can be generated randomly:

  • Integers, Floats & Sequences

  • Strings

  • Vector2, Vector3 & Vector4

  • Extension methods for vectors to generate Colors and Quaternions

  • Export the generated results as text-file

Documentation & control

  • Test all random generators in the editor
  • Powerful API for maximum control
  • Detailed demo scenes
  • Comprehensive documentation and support
  • Full C# source code

Compatibility

  • Supports all build platforms
  • Works with Windows, Mac and Linux editors
  • Compatible with Unity 2019.4 – 2023
  • C# delegates and Unity events

  • Works with Online Check

  • PlayMaker actions

Some impressions:

2966280--768007--CT_Screenshot_06-01-2021-11-39-16-2.jpg

2966280--768010--CT_Screenshot_06-01-2021-11-39-40-9.jpg

2966280--768013--CT_Screenshot_06-01-2021-11-41-16-1.jpg

2966280--768016--CT_Screenshot_06-01-2021-11-43-47-3.jpg

Video:

https://www.youtube.com/watch?v=BsKR3V1EZOU|list=PLgtonIOr6Tb41XTMeeZ836tjHlKgOO84S

AssetStore:
True Random PRO
Essential Tools Bundle
All Tools Bundle

Our other assets

Demo:
WebGL

Changes

Feel free to download and test it.
Any constructive comments are very welcome!

So long,
Stefan

Yeah, our asset is on Max's list:
3087999--232751--Max.PNG

Go there!

Cheers
Stefan

Hi there,
Thanks for True Random, Amazing Plugin,
However calling following function returns 2 same int in result in one case, i though this will always return unique int in result.
TRManager.GenerateInteger(1, TOTAL_ITEMS, REQUIRED_RANDOM_CHARACTER);

It returned
2,2,6,5

Please advise.

Hi John

The “GenerateInteger”-method generates 1-n numbers in a range.
Imaging dices - it’s possible to get the same number twice in two rolls…

What do you want to achive exactly?

So long,
Stefan

1 Like

i want to get unique int to fill a 2d grid with unique characters where each int will represet a unique character.

Can you please add support for getting unique integers so same integer doest appear again?

Isn’t the “GenerateSequence” the solution?

For more see:
https://www.crosstales.com/media/data/assets/truerandom/api/class_crosstales_1_1_true_random_1_1_t_r_manager.html

GenerateSequence doesnt seem to take 3rd parameter which is required, for example
GenerateSequence(1,100, 20);
so i have 100 characters and i want to select only 20 random, which means i should get 20 random ints out of 1-100.

Update:
20 random int means one of 20 int may have a value of "99" and other may have 5, so total 20 ints but values from 1-100

I would do it like this (GetRange does the trick):

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Crosstales.TrueRandom;

public class GetRange : MonoBehaviour {
    public void Start () {
        TRManager.GenerateSequence(1, 100);
    }

    public void OnEnable()
    {
        TRManager.OnGenerateSequenceFinished += onGenerateSequenceFinished;
    }

    public void OnDisable()
    {
        TRManager.OnGenerateSequenceFinished -= onGenerateSequenceFinished;
    }

    private void onGenerateSequenceFinished(List<int> e)
    {
        List<int> relevant = e.GetRange(0, 20);
   
        Debug.Log(relevant.Count);
        Debug.Log(relevant.CTDump());
    }
}

Isn’t that good enough?

Will it Return True Randomness? like other functions?

Yes!

1 Like

Thanks, i'll let you know in case some issue come up.

1 Like

You’re welcome!

If you like our product/support and have some spare time left, please rate us at the store. Or even better, write a review - it’s very much appreciated.
In case you’ve got any further questions, just let me know.

Cheers
Stefan

Hi John

Just to let you know, we added a third parameter “number” for “GenerateSequence”.
If you like to get the new version, send me an email with the invoice.

Cheers
Stefan

1 Like

Hi Stefan,

There is a problem with TrueRandom as it start getting old random results in new reqeusts.

Here is my case.

I make few sequence calls in a fixed order like below, let me call it SequenceOrder
SequenceOrder[
get 4 random numbers,
get 6
get 3
get 2
]
with different min max etc.

i use all these values to construct a character. and so far it worked fine.

now i wanted to see that character in different variations, so what i did is make a list of SequenceOrder like 10 times, and then make those requests 10 times, however this time i see 80% of the character appearing same, when i inspected the results they were 80% same.

Can you please take a look.
Thanks

Hi John

TrueRandom needs to get the random numbers from the Internet, therefor, every request needs time, let’s say 500ms…
If you call “GenerateSequence” without waiting for the results via callback, TR is in fact not finished processing your previous requests and delivers the latest result available. This can result in “the same random results”.
You have to use co-routines and wait, like in this example I made for you:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace Crosstales.TrueRandom.Requests
{
    /// <summary>Tests the generation of multiple sequences.</summary>
    public class SequenceTester : MonoBehaviour
    {
        #region Variables

        public Vector2 RangeA = new Vector2(1, 10);
        public Vector2 RangeB = new Vector2(10, 20);
        public Vector2 RangeC = new Vector2(20, 30);
        public Vector2 RangeD = new Vector2(30, 40);

        public int NumberA = 4;
        public int NumberB = 6;
        public int NumberC = 3;
        public int NumberD = 2;

        public int NumberOfRuns = 10;

        private List<int> valuesA;
        private List<int> valuesB;
        private List<int> valuesC;
        private List<int> valuesD;

        private bool valueGenerated = false;

        private int index = 0;

        #endregion


        #region MonoBehaviour methods

        public void Start()
        {
            StartCoroutine(generateSequences());
        }

        public void OnEnable()
        {
            TRManager.OnGenerateSequenceFinished += onGenerateSequenceFinished;
        }

        public void OnDisable()
        {
            TRManager.OnGenerateSequenceFinished -= onGenerateSequenceFinished;
        }

        #endregion


        #region Private methods

        private IEnumerator generateSequences()
        {
            for (int ii = 0; ii < NumberOfRuns; ii++)
            {
                valueGenerated = false;
                index = 0;

                //values A
                yield return generateSequence((int)RangeA.x, (int)RangeA.y, NumberA);

                //values B
                yield return generateSequence((int)RangeB.x, (int)RangeB.y, NumberB);

                //values C
                yield return generateSequence((int)RangeC.x, (int)RangeC.y, NumberC);

                //values D
                yield return generateSequence((int)RangeD.x, (int)RangeD.y, NumberD);

                Debug.Log("+++ Generating character " + NumberOfRuns + " +++");

                Debug.Log("ValuesA: " + System.Environment.NewLine + valuesA.CTDump());
                Debug.Log("ValuesB: " + System.Environment.NewLine + valuesB.CTDump());
                Debug.Log("ValuesC: " + System.Environment.NewLine + valuesC.CTDump());
                Debug.Log("ValuesD: " + System.Environment.NewLine + valuesD.CTDump());
            }
        }

        private IEnumerator generateSequence(int min, int max, int number)
        {
            TRManager.GenerateSequence(min, max, number);

            while (!valueGenerated)
            {
                yield return null;
            }

            valueGenerated = false;
            index++;
        }

        private void onGenerateSequenceFinished(List<int> e)
        {
            if (index == 0)
            {
                valuesA = e;
            }
            else if (index == 1)
            {
                valuesB = e;
            }
            else if (index == 2)
            {
                valuesC = e;
            }
            else if (index == 3)
            {
                valuesD = e;
            }
            else
            {
                Debug.Log("index out of range!");
            }

            valueGenerated = true;
        }

        #endregion
    }
}

I hope this helps you further.

Cheers
Stefan

Edit:
Script updated

I’m using Events and i wait for answer to come.
OnGenerateSequenceFinished

I’d appreciate if you can take a look because it clearly doesnt work with a complex case where you want to create a truly randomize characcter creater.

My example is exactly doing what you wanted…
Or what isn’t correct with this?

I don’t think this example solves the problem,

I’m doing similar and it works for 2-3 series.

What I’m doing is

Make a request.
+= OnGenerateSequenceFinished
When I get response, I make next request
If no next request I call the final function which draws the character

This is working fine. No issues here. As you can see above strategy wait for the response to come.

Previously [which is working]
Get Ear Graphic from available graphics
Get Nose graphic from available graphics
Get Eye Graphic so on.
Once all got, draw character.

Now when it worked, I felt pressing button and wait for results to come and then see another random result was feeling slow, so I decided to get 10 combinations first and then let user switch to these 10 combinations which means I saved the configuration in loop

loop(10){

Ear Graphic from available graphics
Nose graphic from available graphics
Eye Graphic so on.

}

Now get 1 request one by one using += OnGenerateSequenceFinished
Once all got, draw character from first series of configuraition (which is unique)
Press left and right button to cycle between configurations, and 80% of them are same.

I started to see similar results (which means I’m waiting and getting response, but response is 80% redundant) when I call the above block 10 times.

Hi John

I would like to verify your claim with statistics :slight_smile:
Can you please send me all your character attributes and their exact number of variations?
Probably it’s better do it by email.

So long,
Stefan

Hi Stefan,
Let me replace my code with your and see if that issue persist. if it persist then we both can see the same code, if not, then ill know mistake was on my end :)
Just one more try, and if issue still persisst, ill email you with.
Thanks