Build auto id for any object in inspector

Hello.
I have a variable called “id”.
I want to automatically put a randomistic number when its script is given to the object in the editor.
What should I do to do this?

Make your script executable in edit mode with adding [ExecuteInEditMode] attribute to your script. Then do this:

void OnEnable(){
     if(Application.isEditor) //make sure to get it work only in edit mode or else it will repeat the process in runtime too
     id = (int)Random.Range(0,1000) //numbers are imaginary
}

You can use the InstanceID of the GameObject with GetInstanceID instead of a random ID