Python: Can one call of random.uniform (a,b) influence the outcome of a second call?

I tripple-checked this: the call of the function earlier in my code has an influence on the outcome of a second call (with different variables involved) later on in my code. Random seed is not changed within. I’m puzzled.

10

All PRNGs (Pseudo-Random Number Generators) produce a deterministic sequence of values. When started from the same state, and used in an identical fashion, they will produce the same sequence every time. However, the observed sequence can be affected by using the underlying PRNG for different purposes.

PRNGs are designed to be uniformly distributed over their full range. However, when you choose a sub-range (a,b), the result is usually not uniformly distributed because of the pigeonhole principle — if you distribute more pigeons than there are pigeonholes, some pigeonholes will necessarily have more pigeons than others unless the number of pigeons is an integer multiple of the number of holes.

As a concrete example, suppose you have a 3-bit generator that produces any of 8 values U in the range [0..7], and you want to generate X which has values in the range [0..4]. You might be tempted to use X ← U % 5, but that would give the mapping 0→0, 1→1, 2→2, 3→3, 4→4, 5→0, 6→1, and 7→2. Note that there are twice as many ways to get 0, 1, and 2 than there are to get 3 or 4, so X is not uniformly distributed. Other mapping functions could be used but the pigeonhole principle still applies, so different 1-to-1 mappings would shift around which values occur more frequently but wouldn’t alter that the results are non-uniform.

Because of this, a good library implementation of a sub-range generator will use some form of rejection sampling and discard some of the generated values to achieve uniformity. (See this post for more details.) As a result, most of the raw random numbers are used, but when the rejection criteria are met one (or more) raw values will be discarded and the PRNG state is advanced for each discard. This would affect the observed outcomes of subsequent uses of the underlying generator.

If reproducibility is an issue, one solution for maintaining synchronization across multiple random processes is to create independently seeded PRNG instances for each distinct random process. In other words, don’t use the same PRNG instance to generate uniform(a,b)’s that you use for uniform(c,d)’s.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật