Suppose we possess a text file containing a sequence of millions of randomly generated 0's and 1's, all placed on a single line, like so:
101001011010010011110010001011101010000110101110...
Now, the objective is to utilize this file to generate random decimal fraction numbers, each with precisely 12 decimal places and within the range of 0 to 1:
0.961327557844 0.896041313452 0.144702102262 0.579717079181 0.489590501513 0.116786593965 ... However, this seemingly straightforward task presents a challenge. Each digit must be produced with the same probability without using random functions!
What would be the correct and efficient solution to address this issue and generate random decimal numbers with the desired properties?
I recieved a solution from somebody but it did not work! Step 1: Start by reading the binary data from the file in reasonably sized chunks. Step 2: Convert each binary chunk into an integer. Step 3: Normalize the integer value to obtain a floating-point number between 0 and 1. Step 4: Round the resulting floating-point number to 12 decimal places.
Aucun commentaire:
Enregistrer un commentaire