Given location(x,y,z), check if object exists at that position
If purely creating the random objects...

Here is a test script that places 100 cubes  in scene with integer location components x, y, z selected randomly from range [-10, 10]

Each random location could be added to a list or set when assigned and its contents checked x in [0, 1, 2] Instead I've chosen to use  defaultdict(list), which behaves like a dictionary that returns an empty list() if there is no value for that key.   An empty list is Boolean False ie there is no object in that location..

&gt;&gt;&gt; dd = defaultdict(list)
&gt;&gt;&gt; dd["missing"]
[]


The tuple (x, y, z) is used as a key.    If the key is taken, choose another random number combo, otherwise append to the list of that key marking as taken,  until all cubes placed. 

import bpy
import numpy as np
from collections import defaultdict

ncubes = 100
locations = defaultdict(list)
i = 0
while i &lt; ncubes:
    loc = tuple(np.random.randint(-10, 10, 3))
    if locations[loc]:
        continue

    locations[loc].append(i)
    bpy.ops.mesh.primitive_cube_add(location=loc)
    i += 1


Without checking against already existing objects in a scene this is pretty much purely a python problem. A good place to find answers to python questions is https://stackoverflow.com