Example #1
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Generate pseudo random numbers. Should not be used for security purposes."""

from '__go__/math/rand' import Uint32, Seed
from '__go__/math' import Pow
from '__go__/time' import Now


BPF = 53  # Number of bits in a float
RECIP_BPF = Pow(2, -BPF)


# TODO: The random byte generator currently uses math.rand.Uint32 to generate
# 4 bytes at a time. We should use math.rand.Read to generate the correct
# number of bytes needed. This can be changed once there is a way to
# allocate the needed []byte for Read from python and cast it to a list of
# integers once it is filled.
def _gorandom(nbytes):
  byte_arr = []
  while len(byte_arr) < nbytes:
    i = Uint32()
    byte_arr.append(i & 0xff)
    byte_arr.append(i >> 8 & 0xff)
    byte_arr.append(i >> 16 & 0xff)
    byte_arr.append(i >> 24 & 0xff)
Example #2
0
def pow(x, y):
    return Pow(float(x), float(y))