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.
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.
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);
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
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.
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.
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.
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’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.
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.
I would like to verify your claim with statistics
Can you please send me all your character attributes and their exact number of variations?
Probably it’s better do it by email.
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