Conversation
Azrael3000
left a comment
There was a problem hiding this comment.
Will not merge this in the current state, this needs reworking.
| // used in Variable::random_seed() | ||
| if(me == 0){ | ||
| // NOTE: better random generator for random_seed()? | ||
| srand(time(NULL)); |
There was a problem hiding this comment.
This will cause random numbers to be truly random, which is something you don't want as it destroys repeatability.
There was a problem hiding this comment.
This is my point. If I want to repeat my simulation, I can use a predefined seed, but if I want to repeat an "experiment" with "random" particle positions, I can use randomseed().
There was a problem hiding this comment.
Could create a list of, say 500, prime numbers given an initial seed. If someone provides 0, you get the current behavior, and for any other number you get a list of semi-random numbers that is repeatable. Then every call to randomseed simply increments the location in the pre-compiled list.
You would also be able to add additional checks that make sure each prime number is unique.
src/variable.cpp
Outdated
| static const int SEED_RANGE = (LAST_PRIME - FIRTS_PRIME) + 1; | ||
|
|
||
| if(me == 0){ | ||
| while(!MathExtraLiggghts::isPrime(seed)){ |
There was a problem hiding this comment.
This algorithm is really bad in terms of performance. Using lookup tables would be much better.
There was a problem hiding this comment.
Agreed, I'm afraid a list would be too big to hold it in the memory (105'097'397 numbers). I'll try to come up with a faster solution.
There was a problem hiding this comment.
You could use the fact that all prime numbers greater than 3, are of the form 6k-1 or 6k+1.
Randomly taking k from an initial value of 20600, you get a valid prime about 30% of the time. But you do have to check if two different numbers are prime.
There was a problem hiding this comment.
Thanks! I'll look into that.
doc/variable.txt
Outdated
| random(x,y,z), normal(x,y,z), ceil(x), floor(x), round(x) | ||
| ramp(x,y), stagger(x,y), logfreq(x,y,z), stride(x,y,z), vdisplace(x,y), swiggle(x,y,z), cwiggle(x,y,z) | ||
| ramp(x,y), stagger(x,y), logfreq(x,y,z), stride(x,y,z), vdisplace(x,y), swiggle(x,y,z), cwiggle(x,y,z), | ||
| randomseed(0) |
There was a problem hiding this comment.
having an unused argument is not good practice. Rewrite the interface instead.
There was a problem hiding this comment.
Agreed, but the parser for variable equal expects at least 1 argument for functions, if I understand the code rigth.
The
seed(n)function generates a prime number between 10000 and INT_MAX (2147483647). The output of this function can be used to be the seed of particletemplate, particledistribution, etc.If the argument is 0, a random prime number is generated, else the n-th greater, than 10000 prime (n = 1 -> 10007, n = 2 -> 10009, etc) is the output.