C
C#6mo 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
GavkoShmigOP6mo ago
I can interact only with a. I cant write any other external method
Jimmacle
Jimmacle6mo 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
GavkoShmigOP6mo ago
sad
Jimmacle
Jimmacle6mo ago
you want a method, not a variable methods do things when you call them
GavkoShmig
GavkoShmigOP6mo 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
Jimmacle6mo 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
GavkoShmigOP6mo ago
thats what im talking about is there some unity component
Jimmacle
Jimmacle6mo ago
i'm sure unity has a random class check their docs
GavkoShmig
GavkoShmigOP6mo ago
yes but once assigned it wont change
Jimmacle
Jimmacle6mo ago
correct
GavkoShmig
GavkoShmigOP6mo ago
mhm ok
Jimmacle
Jimmacle6mo ago
you have to change it if you want it to change
GavkoShmig
GavkoShmigOP6mo ago
thx for help
SleepWellPupper
SleepWellPupper6mo ago
Can you not use a method or property instead of a?
Want results from more Discord servers?
Add your server