rewrite randomDataOfLength as C function