How do I get multiple Random.ranges from one script

I’m trying to get a bunch of npc’s to patrol randomly. I use Random.range to spawn a new position, and then i move the npc to that new position. I have the same script on all the NPC’s, so they’re using the same Random.Range, so they end up going to the same position. I’m using Random.Range to control how long they pause for inbetween moving, and again, they pause for the same amount of time. I think its important they use the same script, because I want to use lots of npc’s in the one scene, and i dont want to make a new script for every npc. I’m really stumped. Is there a standard way of managing lots of randomness? I cant seem to find one.

Heres my script:

    private Animator animator;
    private SpriteRenderer spriteRenderer;

    public float speed;
    private float waitTime;
    public float startWaitTimeMin;
    public float startWaitTimeMax;

    public Transform moveSpot;
    public float minX;
    public float maxX;
    public float minY;
    public float maxY;

 
    void Start()
    {
        animator = GetComponent<Animator>();
        spriteRenderer = GetComponent<SpriteRenderer>();

        waitTime = Random.Range(startWaitTimeMin, startWaitTimeMax);

        moveSpot.position = new Vector2(Random.Range(minX, maxX), Random.Range(minY, maxY));
    }

    void Update()
    {
        transform.position = Vector2.MoveTowards(transform.position, 
        moveSpot.position, speed * Time.deltaTime);


        if (Vector2.Distance(transform.position, moveSpot.position) < 0.2f)
        {
            if (waitTime <= 0)
            {
                moveSpot.position = new Vector2(Random.Range(minX, maxX), Random.Range(minY, maxY));
                animator.SetBool("isWalking", true);
                waitTime = Random.Range(startWaitTimeMin, startWaitTimeMax);
            }
            else
            {
                animator.SetBool("isWalking", false);
                waitTime -= Time.deltaTime;
            }
        }
    }

Random.Range will return a different random value each time it is called. However you seem to reference a gameobject with your “moveSpot” reference. Are you sure that each of your NPC has it’s own Transform object? If they all use the same object, of course they will all move to the same position. When each NPC is setting the position of that one object, they will just overwrite each other and only the last assignment would take effect.

Why do you actually use a Transform? Since you only need a target location, you probably should simply store the target position in a Vector3 variable, so each NPC has it’s own target. If for some reason you want / need to use an actual gameobject for the target position, make sure every NPC has it’s own moveSpot gameobject and that each NPC is actually referencing their own.