MoveTowards doesn't work

Here is the code:

target = new Vector3 (Random.Range (-4.7f, 0), Random.Range (-2.75f, 3.5f), 0);
            // Move to the random position
            transform.position = Vector3.MoveTowards (transform.position,
                target, speed * Time.deltaTime);

I want to move my gameobject automatically but it turns out that the gameobject only move a very short distance. I put it in Update() and make a if statement which used to control my gameobject stop until it move to the random position

If that code is in Update, then each frame you’re finding a new random position, moving a little bit towards it, and then next frame you’re getting a new random position, moving a little towards it, etc. You need to pick one random position and store it in a variable, so that “target” is the same every update until transform.position is equal to target, or you otherwise want to stop the movement.