random doc logic