C
C#4w ago
GavkoShmig

replace variable with random number

so lets say I have int a = something what do I put instead of something to make a change value each time its called for example:
Console.WriteLine(a);
Console.WriteLine(a);


output:
1
8
Console.WriteLine(a);
Console.WriteLine(a);


output:
1
8
14 Replies
GavkoShmig
GavkoShmig4w ago
I can interact only with a. I cant write any other external method
Jimmacle
Jimmacle4w ago
Random.Shared.Next() but you can't do exactly what you're asking a variable can't magically change when you retrieve the value, you need to write code that changes it
GavkoShmig
GavkoShmig4w ago
sad
Jimmacle
Jimmacle4w ago
you want a method, not a variable methods do things when you call them
GavkoShmig
GavkoShmig4w ago
ik I need this for a unity game are there any unity components that can do this f.e. on start change specific variable
Jimmacle
Jimmacle4w ago
nothing will do exactly what you want because variables can't change by themselves you need more code that changes them when you want them to change
GavkoShmig
GavkoShmig4w ago
thats what im talking about is there some unity component
Jimmacle
Jimmacle4w ago
i'm sure unity has a random class check their docs
GavkoShmig
GavkoShmig4w ago
yes but once assigned it wont change
Jimmacle
Jimmacle4w ago
correct
GavkoShmig
GavkoShmig4w ago
mhm ok
Jimmacle
Jimmacle4w ago
you have to change it if you want it to change
GavkoShmig
GavkoShmig4w ago
thx for help
SleepWellPupper
Can you not use a method or property instead of a?