Trying to get AI to move for a randomly selected amount of time then turn around

Trying to get my AI to move either left or right for a random amount of time. I did this by using a bunch of bool’s to figure out other things. Just need some help because when I start it up, it doesn’t move at all right now, but before when I didn’t have all the boolean checks, it accelerated forever.

Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class enemyAI : MonoBehaviour
{

public float Speed;
public float maxSpeed;
public bool goingLeft;
public bool patrolling;
public bool end;
public float patrolValues;
public float Health = 1f;
public Rigidbody2D rb;
public Animator anim;

private void Start()
{
    goingLeft = true;
    patrolValue();
    patrolling = false;

}

//AI Health Mechanic

//everything under this point is the patrol stuff
private void OnCollisionStay2D(Collision2D collision)
{
    if (collision.collider.gameObject.layer == LayerMask.NameToLayer("Ground"))
    {
        patrolStart();
        

    }

}

void patrolStart()
{
   
    if (!patrolling && !end)
    {
        Patrol();

    }

}

void patrolValue()
{
    
    
        patrolValues = Random.Range(1f, 2f);
        Patrol();
        StartCoroutine(patrolLength());

}

void Patrol()
{
    if (goingLeft)
    {
        if (!end)
        {
            rb.AddForce(transform.right * -Speed);
            patrolling = true;
            
        }
            
        
        
    }
    else
    {

        if (!end)
        {
            rb.AddForce(transform.right * Speed);
            patrolling = true;
            
        }
        
    }
}

void TurnAround()
{
    
    goingLeft = !goingLeft;
    patrolling = false;
    Patrol();

}

IEnumerator patrolLength()
{
    yield return new WaitForSeconds(patrolValues * 10);
    TurnAround();
    end = true;

}

}

I don’t totally understand you code here, but here is a solution I came up with that should work. Maybe it’ll give you some ideas.

float patrolAmount;
int patrolDirection;
bool patrolling;

private void Start(){
	patrolAmount = Random.Range(1f, 2f);
	patrolling = true;
	patrolDirection = 1;
	StartCoroutine(Patrol());
}

private void FixedUpdate(){
	if (patrolling)
		rb.AddForce(transform.right * Speed * patrolDirection);
}

private IEnumerator Patrol(){
	while (true){
		if (!patrolling)
			yield break;
		patrolAmount -= Time.deltaTime;
		if (patrolAmount < 0)
		{
			patrolAmount = Random.Range(1f, 2f);
			patrolDirection *= -1;
		}	
		yield return new WaitForEndOfFrame();
	}
}