AI placement of ships (battleship game)

Hi im making this game and this is the last cinderlbock i need to get through to make it remotly playable. The game is battleships where you place your ships and you and the computer takes turn to shoot at eachothers grids. I need the computer A.I to place its own ships randomly and according to the rules. It will place the battleship first which is (4x1) and then 2 cruisers (3x1) and then 3 destroyers (2x1) and lastly four submarines (1x1). These cannot touch eachother on the sides or on the corners and they can be placed outside the 10x10 grid board. I honestly have no idea how im gonna make this. If somebody has worked with this or can give some tips or starting point on how i should do i would be glad to.

have you found a solution to this? I’m trying to do the exact same thing.