Enemy avoidance script

Hi guys I have a script I am currently using that when the character has come within a certain distance the enemy runs away, my problem is that the enemy sometimes just turns around and runs right back into a character. I have looked into a Nav Mesh but decided that it didn’t go with my requirements. I was just wondering if someone could post a script that could make the enemy run away from the character. I would not like to use path finding either just a simple code that the enemy runs away from the character and randomly turns but always away from the character never towards the character.

Not sure if this will help but try this:

First ray cast in 4 directions.(along x and z axis)
Ray cast must be set like 10 meters(depends on size of map and etc)
Make four variables for each ray cast and if a ray cast is hit then set that variable to true.

public bool WallToTheLeft = false;
public bool WallToTheRight = false;
public bool WallToTheFront = false;
public bool WallToTheback = false;

//If the ray cast to the left of the enemy has hit a wall then
WallToTheLeft = true

//If the ray cast to the right of the enemy has hit a wall then
WallToTheRight = true

//If the ray cast to the front of the enemy has hit a wall then
WallToTheFront = true

//If the ray cast to the back of the enemy has hit a wall then
WallToTheback = true

// when the enemy must run from the player
if(WallToTheback == false)
{
       this.getcomponent<NavMeshAgent>().SetDestination(this.transform.back * 10)
}
else
{
      //find path left or right
}