random data function improved