GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Simplify _rand_exp · Issue #7 · fuzzitdev/pythonfuzz

This repository was archived by the owner on Apr 30, 2021. It is now read-only.
This repository was archived by the owner on Apr 30, 2021. It is now read-only.

Simplify _rand_exp #7

Copy link
Copy link
Open
Open
Simplify _rand_exp#7
Copy link

Description

@jvoisin
jvoisin
opened on Dec 16, 2019
Issue body actions

The current _rand_exp is currently looking suboptimal:

    # Exp2 generates n with probability 1/2^(n+1).                               
    @staticmethod                                                                
    def _rand_exp():                                                                                                                                                                   
        rand_bin = bin(int(random.random() * 2**32-1))[2:]                       
        rand_bin = '0'*(32 - len(rand_bin)) + rand_bin                           
        count = 0                                                                
        for i in rand_bin:                                                       
            if i == '0':                                                         
                count +=1                                                        
            else:                                                                
                break                                                            
        return count

Am I misreading the code and the comment, or is it equivalent to int(random.expovariate(0.5))?

Activity

  1. yevgenypats commented on Dec 18, 2019

    @yevgenypats
    yevgenypats
    on Dec 18, 2019
    More actions

    _rand_exp generates a number from 0-32 I'm don't see how it's equivalent to int(random.expovariate(0.5)) but maybe I'm missing something. I also searched a better way to implement this when I ported this part from go-fuzz but didn't find anything "built-in"

  2. jvoisin commented on Dec 18, 2019

    @jvoisin
    jvoisin
    on Dec 18, 2019
    ContributorAuthor
    More actions

    Then the comment above the function should be fixed/improved I think :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.