Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6545789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:37:43+00:00 2026-05-25T11:37:43+00:00

I am converting some c code to python. I am wondering that is there

  • 0

I am converting some c code to python. I am wondering that is there any drand48() equivalent in python(exactly the same!) or a wrapper to it?

Thanks a lot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:37:43+00:00Added an answer on May 25, 2026 at 11:37 am

    You are looking for random.random.

    >>> import random
    >>> help(random)
    >>> random.random()
    0.8423026866867628
    

    It does not use the same generator as drand48. The drand48 family uses a 48-bit linear congruential generator, whereas the Python random module uses the superior Mersenne Twister algorithm.

    If you want the exact same output as drand48, you can implement it in Python.

    # Uncomment the next line if using Python 2.x...
    # from __future__ import division
    class Rand48(object):
        def __init__(self, seed):
            self.n = seed
        def seed(self, seed):
            self.n = seed
        def srand(self, seed):
            self.n = (seed << 16) + 0x330e
        def next(self):
            self.n = (25214903917 * self.n + 11) & (2**48 - 1)
            return self.n
        def drand(self):
            return self.next() / 2**48
        def lrand(self):
            return self.next() >> 17
        def mrand(self):
            n = self.next() >> 16
            if n & (1 << 31):
                n -= 1 << 32
            return n   
    

    However, the output will be significantly inferior to Python’s standard random number generator. The rand48 family of functions were declared obsolete in 1989 by SVID 3.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am converting some code from another language to python. That code reads a
I've got some C# code that I'm converting to Objective-C. In C# I would
I'm converting some java code to python code and I ended up getting stumped
I'm trying to use OpenCV with Python and converting some C++ code. Anyway, if
I have some python code that does a certain task. I need to call
I'm converting some code that currently uses an XmlWriter to create a document to
I am converting some code to LINQ, at the same time exploring to what
I am converting some code to Scala. It's code that sits in an inner
I am converting some Java code to C#. This code is using getGlyphOutline from
Searching for some sample code for converting a point in WGS84 coordinate system to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.