#Weird random not being random bug
1 messages · Page 1 of 1 (latest)
Again, it's always 977? Every time you run the game it does that?
Then you are definitely setting the random seed somewhere
No, I mean the Unity Random Seed
the thing that generates your randoms
not your variable seed
Should I use system.random instead? maybe thatll help?
Somewhere in your code you are calling Random.InitState and giving it the same values
Random.InitState((int)DateTime.Now.Ticks);
If anything in your project sets InitState, it's shared for all randomness in the project
as a test try that
but yeah i would search the whole project including 3rd party packages for a call to InitState
My Broccoli Tree Creator asset apparently calls
UnityEngine.Random.InitState (srcInt);
That'd do it
there is the problem then
Should I call this before the seed is generated?
oh neverind
would not bother with this now that you found where its being messed with
lol alright
generally since UnityEngine.Random is global best not to have anything mess with its state
that kind of sucks, bought the tree creator asset for $45
if you need a instance of a random where you control the seed manually i would use System.Random for that
alright thank you
yeah its sucks since the unity one, has a bunch of nice things for gamedev
like Random.insideUnitCircle/Sphere
it's still worth the purchase though, i modified the asset and integrated it so it can generate trees procedurally for the entire game
one of my main goals was to have a unique tree for every world, every tree
for the tree creator?
more or less what you are seeing is when the seed is a constant and is the same for each run
yeah, i assume it's because the date.now doesnt go into miliseconds
and maybe just days
this actually explains why some of the trees have very similar shapes and sizes, then very different ones the next day
huh
// Generate consistent color for a type - using string because it delivers greater variety of colors than type hashcode
int srcInt = (int)(type.AssemblyQualifiedName.GetHashCode ());
UnityEngine.Random.InitState (srcInt);
Color = UnityEngine.Random.ColorHSV (0, 1, 0.6f, 0.8f, 0.8f, 1.4f);```
ill show a snippet because it is a unity asset store product
hmm there must be more places its using it
thats a really weird usage since that would be the same seed everytime, looks like they were trying to be too clever
yeah it happens for a few more documents
should I try changing it?
ive already modified the asset a few times so
could do that, or reseed it to something after you know all of them have already executed
like my example that used (int)DateTime.Now.Ticks
yeah that would make more sense