java - c strange use of srand and rand c -
can me understand meaning of these randomization?
i have found in c code have translate, return 41:
int main(){ srand(1); printf("\n%d",rand()); }
how can emulate srand(1) , rand() in java?
my answer assumes want emulate behavior of srand() , rand(), not care '41' get.
this idea of pseudo-random number generation. if set seed constant value (1 in case), call random() function, return same value. because saying "set index 1 in big list of 'random' numbers" next time call random returns n-th value in 'list'. in reality, bit more complex, that's how think sometimes. emulate behavior of code in java, can try following:
public static void main(string[] args) { random rand = new random(1); system.out.println(string.valueof(rand.nextint())); }
Comments
Post a Comment