- Home /
Random Numbers and related scripts
Does anyone know how to implement the following? I work with Javascript at the moment so C# is new to me.
http://www.unifycommunity.com/wiki/index.php?title=CustomRandom
I tried this in Javascript:
function Update ()
{ var randNum = CustomRandom(); Debug.Log(randNum); }
I did that because I can't attach the CustomRandom script to an object.
Any help is appreciated. Thanks.
Answer by jahroy · Apr 23, 2011 at 04:13 AM
Is there any reason why you can't use the normal random number generators?
/* generate a random number between 0 and 1 */
var randomNumber = Random.value;
/ generate a random number between 0 and 10 /
var randomNumber = 10 * ( Random.value );
/ generate a random number between 10 and 20 /
var randomNumber = Random.Range(10, 20);
Also...
If you're going to try to use that code, you probably want to use calls to functions like this:
/* instantiate a random number generator */
CustomRandom randomNumberGenerator = new CustomRandom();
/ call some functions to generate random numbers /
float randomNumber = randomNumberGenerator.NextDouble(); float notSoRandom = randomNumberGenerator.about(5, 1.2);
Your code looks like it tries to call the constructor and assign the result (which is nothing) to a variable.
Yeah they are good for small things, but for extensive randomization I need something more robust.
Answer by Eric5h5 · Apr 23, 2011 at 04:17 AM
What is the question exactly? Your code is OK as far as it goes, but you'd want to use a property of your randNum variable somehow. That wiki code doesn't really seem to be documented though. You'd be better off using System.Random.
Well the wiki code is in C#, and there fore another script. It is not attached to anything. How would I access it from another code written in Javascript?
Your answer
Follow this Question
Related Questions
Random Number Generator 4 Answers
Randome Number for Dice 2 Answers
How to prevent picking the same combination in array? 1 Answer
Generate random number 4 Answers
Random int 1 Answer