Skip to main content
Log in

Exact Sublinear Binomial Sampling

  • Published:
Algorithmica Aims and scope Submit manuscript

Abstract

Drawing a random variate from a given binomial distribution B(np) is an important subroutine in many large-scale simulations. The naive algorithm takes \(\mathcal {O}(n)\) time w.h.p. in the WordRAM model, which is too slow in many settings, though to its credit, it does not suffer from precision loss. The problem of sampling from a binomial distribution in sublinear time has been extensively studied and implemented in such packages as R [22] and the GNU Scientific Library  [11], however, all previous sublinear-time algorithms involve precision loss, which introduces artifacts such as discontinuities into the sampling. In this paper, we present the first algorithm, to the best of our knowledge, that samples binomial distributions in sublinear time with no precision loss. We assume that each bit of p can be obtained in \(\mathcal {O}(1)\) time.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Fig. 1
Fig. 2
Fig. 3

Similar content being viewed by others

Notes

  1. The exponent of the polylog is not specified in their paper, and depends on such factors as the runtime to compute the digits of \(\sqrt{2\pi }\), but we note here that it is more than 1.

References

  1. Abe, J., Kamimura, Y.: Do female parasitoid wasps recognize and adjust sex ratios to build cooperative relationships? J. Evol. Biol. 25(7), 1427–1437 (2012)

    Article  Google Scholar 

  2. Ahrens, J.H., Dieter, U.: Sampling from binomial and Poisson distributions: A method with bounded computation times. Computing 25(3), 193–208 (1980)

    Article  MathSciNet  MATH  Google Scholar 

  3. Batagelj, V., Brandes, U.: Efficient generation of large random networks. Phys. Rev. E 71(3), 36113 (2005)

    Article  Google Scholar 

  4. Blanca, A., Mihail, M.: Efficient generation \(\varepsilon \)-close to G(n,p) and generalizations. CoRR (2012). arXiv:1204.5834

  5. Bringmann, K., Friedrich, T.: Exact and efficient generation of geometric random variates and random graphs. In: Fomin, F.V., Freivalds, R., Kwiatkowska, M.Z., Peleg, D. (eds.) Automata, Languages, and Programming (ICALP), vol. 7965, pp. 267–278. Springer, Berlin, Heidelberg (2013)

  6. Bringmann, K., Kuhn, F., Panagiotou, K., Peter, U., Thomas, H.: Internal dla: Efficient simulation of a physical growth model. In: Esparza, J., Fraigniaud, P., Husfeldt, T., Koutsoupias, E. (eds.) Automata, Languages, and Programming (ICALP), vol. 8572, pp. 247–258. Springer, Berlin, Heidelberg (2014)

  7. Devroye, L.: Generating the maximum of independent identically distributed random variables. Comput. Math. Appl. 6(3), 305–315 (1980)

    Article  MathSciNet  MATH  Google Scholar 

  8. Devroye, L.: Non-Uniform Random Variate Generation. Springer, Berlin (1986)

    Book  MATH  Google Scholar 

  9. Farach-Colton, M., Tsai, M.T.: Exact sublinear binomial sampling. In: Cai, L., Cheng, S.-W., Lam, T.W. (eds.) Algorithms and Computation (ISAAC), vol. 8283, pp. 240–250. Springer, Berlin, Heidelberg (2013)

  10. Fox, J., Weisberg, S.: An R Companion to Applied Regression. Sage Publications, New York (2010)

    Google Scholar 

  11. Galassi, M.: Gnu Scientific Library: Reference Manual (2003)

  12. Granlund, T.: The GMP Development Team. GNU MP: The GNU Multiple Precision Arithmetic Library (2012)

  13. Hörmann, W.: The generation of binomial random variates. J. Stat. Comput. Simul. 46(1–2), 101–110 (1993)

    Article  MATH  Google Scholar 

  14. Hörmann, W., Leydold, J., Derflinger, G.: Automatic Nonuniform Random Variate Generation. Springer, Berlin (2004)

    Book  MATH  Google Scholar 

  15. Kachitvichyanukul, V., Schmeiser, B.W.: Binomial random variate generation. Commun. ACM 31(2), 216–222 (1988)

    Article  MathSciNet  Google Scholar 

  16. Karney, C.F.F.: Sampling exactly from the normal distribution. CoRR (2013). arXiv:1303.6257

  17. Knuth, D., Yao, A.: Algorithms and Complexity: New Directions and Recent Results, Chap. The Complexity of Nonuniform Random Number Generation. Academic Press, Waltham (1976)

    Google Scholar 

  18. Knuth, D.E.: The Art of Computer Programming: Seminumerical Algorithms, vol. 2. Addison-Wesley, Boston (1997)

    Google Scholar 

  19. Kronmal, R.A., Peterson, A.V.J.: On the alias method for generating random variables from a discrete distribution. Am. Stat. 33(4), 214–218 (1979)

    MathSciNet  MATH  Google Scholar 

  20. Miller, J.C., Hagberg, A.: Efficient generation of networks with given expected degrees. In: Frieze, A.M., Horn, P., Pralat, P. (eds.) Algorithms and Models for the Web Graph (WAW), vol. 6732, pp. 115–126. Springer, Berlin, Heidelberg (2011)

  21. Patterson, R.S., Louisville, U.: Testing the Effects of Predictors Using Data Generated by Non-identity Link Functions of the Single-Index Model: A Monte Carlo Approach. University of Louisville, Louisville (2008)

    Google Scholar 

  22. R Development Core Team: R: A Language and Environment for Statistical Computing (2008)

  23. Stadlober, E., Zechner, H.: The patchwork rejection technique for sampling from unimodal distributions. Trans. Model. Comput. Simul. 9(1), 59–80 (1999)

    Article  Google Scholar 

  24. Stillwell, J.: Elements of Number Theory. Springer, Berlin (2003)

    Book  MATH  Google Scholar 

  25. Tsai, M., Wang, D., Liau, C., Hsu, T.: Heterogeneous subset sampling. In: Thai, M.T., Sahni, S. (eds.) Computing and Combinatorics (COCOON). vol. 6196, pp. 500–509. Springer, Berlin, Heidelberg (2010)

Download references

Acknowledgments

We sincerely thank the reviewers for their helpful commments.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Meng-Tsung Tsai.

Additional information

This research was supported by NSF Grants IIS-1247750 and CCF-1114930.

Rights and permissions

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Farach-Colton, M., Tsai, MT. Exact Sublinear Binomial Sampling. Algorithmica 73, 637–651 (2015). https://doi.org/10.1007/s00453-015-0077-8

Download citation

  • Received:

  • Accepted:

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s00453-015-0077-8

Keywords

Navigation