🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

How to change seed for random coordinate generation in the API?

User: "satri"
Altair Community Member
Updated by satri

I am trying to generate random coordinates between -150.0E-6 to 150.0e-6 but when i use this function 

image

I get random coordinates but when i repeat the simulation i get the same set of coordinates. so i am trying to change the seed of the random number generator. Hence I try this to change the seed value

Hence i tried to generate a random integer using srand function but this gives me numbers  which are not random they give me one random coordinate and all other random coordinates stack on top of each other.

image

Please tell me how to change the seed value for the random number generator

Find more posts tagged with

Sort by:
1 - 5 of 51
    User: "jerrinjobs"
    Altair Employee
    Updated by jerrinjobs

    Hi Shyam

    Please check the following link to get a better understanding of the srand function: https://cplusplus.com/reference/cstdlib/srand/

    Thanks,
    Jerrin Job

    User: "satri"
    Altair Community Member
    OP
    Updated by satri

    Yes i wrote those lines which are commented out in green based on this (https://cplusplus.com/reference/cstdlib/srand/)

    I am not trying to say i get same x y coordinates for that if i include srand in between ThisRandNuX and thisRandNuY i will get different random number.

    What i am trying to ask is

    Say i want to generate 10 particles, if i run the lines which are commented out (ones in green)

    i will get same random number for 1st particle.. 2nd particle..3rd particle etc.

    Why do i not get a different random number? Thats is what i am trying to ask.

    When a new particle is about to be generated 

    srand(::time(NULL)) line will re-run and i expected to see a different random number for particle 2 and 3 etc..

    User: "Renan"
    Altair Employee
    Accepted Answer
    Updated by Renan

    Hi Shyam,

    Here's a detailed solution to your problem regarding random numbers generation and why you should avoid the rand function : https://stackoverflow.com/questions/288739/generate-random-numbers-uniformly-over-an-entire-range

    Regards,
    Renan

    User: "satri"
    Altair Community Member
    OP
    Updated by satri

    I tried the one you suggested from stack overflow everytime it gives the same pattern 

    image

    positioning i will fix it but it gives the same pattern every time i want the pattern to change when i run the simulation next time

    image

    User: "satri"
    Altair Community Member
    OP
    Updated by satri

    never mind please ignore it. that code works i fixed the positions..i have to give it a minute for the pattern to change