A method for generating a signal comprising a sequence of random bits, comprising the steps of: - measuring a first quadrature p̂ of an electromagnetic field, - sampling the measurement of the first quadrature p̂ so as to obtain a first sequence of samples, - generating a first sequence of bits by means of a binary encoding of the first sequence of samples, - measuring of a second quadrature q̂ of the electromagnetic field, - sampling the measurement of the second quadrature q̂ so as to obtain a second sequence of samples, - generating a second sequence of bits by means of a binary encoding of the sequence of samples, - generating a third sequence of bits by means of a randomness extractor algorithm, wherein the randomness extractor algorithm receives the said first sequence of bits and a parameter and reduces the bit length of the first sequence of bits in dependence on the parameter, in such a way as to generate a third sequence of bits with a randomness greater than that of said first sequence of bits, said parameter provided as an input to the randomness extractor algorithm and being a function of the maximum entropy value of a random variable Q associated with the second sequence of bits, wherein said parameter is calculated as: lo g 2 h δqδq R 00 1, δqδq 4 − 1 − H max Q ω where: ▪ δp and δq are the uncertainties of the measurements made on the first quadrature p̂ and second quadrature q̂, ▪ the term R 00 1, δqδp 4 is a prolate spheroidal radial wave function of the first kind; ▪ H max Q ω = 2 lo g 2 ∑ i = 0 n − 1 Pr Q = q i is the maximum entropy of the random variable Q associated with the second quadrature q̂ for a state ω and corresponds to a Rényi entropy of the order 1⁄2 of said random variable Q, - generating a signal containing the third sequence of bits. - measuring a first quadrature p̂ of an electromagnetic field, - sampling the measurement of the first quadrature p̂ so as to obtain a first sequence of samples, - generating a first sequence of bits by means of a binary encoding of the first sequence of samples, - measuring of a second quadrature q̂ of the electromagnetic field, - sampling the measurement of the second quadrature q̂ so as to obtain a second sequence of samples, - generating a second sequence of bits by means of a binary encoding of the sequence of samples, - generating a third sequence of bits by means of a randomness extractor algorithm, wherein the randomness extractor algorithm receives the said first sequence of bits and a parameter and reduces the bit length of the first sequence of bits in dependence on the parameter, in such a way as to generate a third sequence of bits with a randomness greater than that of said first sequence of bits, said parameter provided as an input to the randomness extractor algorithm and being a function of the maximum entropy value of a random variable Q associated with the second sequence of bits, wherein said parameter is calculated as: lo g 2 h δqδq R 00 1, δqδq 4 − 1 − H max Q ω where: ▪ δp and δq are the uncertainties of the measurements made on the first quadrature p̂ and second quadrature q̂, ▪ the term R 00 1, δqδp 4 is a prolate spheroidal radial wave function of the first kind; ▪ H max Q ω = 2 lo g 2 ∑ i = 0 n − 1 Pr Q = q i is the maximum entropy of the random variable Q associated with the second quadrature q̂ for a state ω and corresponds to a Rényi entropy of the order 1⁄2 of said random variable Q, ▪ δp and δq are the uncertainties of the measurements made on the first quadrature p̂ and second quadrature q̂, ▪ the term R 00 1, δqδp 4 is a prolate spheroidal radial wave function of the first kind; ▪ H max Q ω = 2 lo g 2 ∑ i = 0 n − 1 Pr Q = q i is the maximum entropy of the random variable Q associated with the second quadrature q̂ for a state ω and corresponds to a Rényi entropy of the order 1⁄2 of said random variable Q, - generating a signal containing the third sequence of bits.