Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

Python 2, 75 69 bytes

from random import*;s=0;j=randrange
while j(12):s=s*9+j(-8,9)
print s

It is trivial to check that the while loop in the middle can generate all integers (albeit biased towards zero). "12" is chosen such that there are roughly half of numbers exceeding ±106.


Older solution:

Python 2, 44 bytes

Based on the Mathematica solutionMathematica solution.

from random import*;print int(gauss(0,8**7))

Doesn't really work because Python's float has only finite precision.

Python 2, 75 69 bytes

from random import*;s=0;j=randrange
while j(12):s=s*9+j(-8,9)
print s

It is trivial to check that the while loop in the middle can generate all integers (albeit biased towards zero). "12" is chosen such that there are roughly half of numbers exceeding ±106.


Older solution:

Python 2, 44 bytes

Based on the Mathematica solution.

from random import*;print int(gauss(0,8**7))

Doesn't really work because Python's float has only finite precision.

Python 2, 75 69 bytes

from random import*;s=0;j=randrange
while j(12):s=s*9+j(-8,9)
print s

It is trivial to check that the while loop in the middle can generate all integers (albeit biased towards zero). "12" is chosen such that there are roughly half of numbers exceeding ±106.


Older solution:

Python 2, 44 bytes

Based on the Mathematica solution.

from random import*;print int(gauss(0,8**7))

Doesn't really work because Python's float has only finite precision.

added 286 characters in body
Source Link
kennytm
  • 7k
  • 19
  • 47

Python 2, 7575 69 bytes

from random import*;s=0;j=randrange
while j(1112):s=s*11+js=s*9+j(11-8,9)
print s/2^s%-2

It is trivial to check that the while loop in the middle can generate all integers (albeit biased towards zero). "11""12" is chosen such that there are roughly half of numbers exceeding 2×10±106. The final print code transforms the range from nonnegative integers to all integers.


Older solution:

Python 2, 44 bytes

Based on the Mathematica solution.

from random import*;print int(gauss(0,8**7))

Doesn't really work because Python's float has only finite precision.

Python 2, 75 bytes

from random import*;s=0;j=randrange
while j(11):s=s*11+j(11)
print s/2^s%-2

It is trivial to check that the while loop in the middle can generate all integers (albeit biased towards zero). "11" is chosen such that there are roughly half of numbers exceeding 2×106. The final print code transforms the range from nonnegative integers to all integers.


Older solution:

Python 2, 44 bytes

Based on the Mathematica solution.

from random import*;print int(gauss(0,8**7))

Doesn't really work because Python's float has only finite precision.

Python 2, 75 69 bytes

from random import*;s=0;j=randrange
while j(12):s=s*9+j(-8,9)
print s

It is trivial to check that the while loop in the middle can generate all integers (albeit biased towards zero). "12" is chosen such that there are roughly half of numbers exceeding ±106.


Older solution:

Python 2, 44 bytes

Based on the Mathematica solution.

from random import*;print int(gauss(0,8**7))

Doesn't really work because Python's float has only finite precision.

Post Undeleted by kennytm
added 286 characters in body
Source Link
kennytm
  • 7k
  • 19
  • 47

Python 2, 4475 bytes

Based on the Mathematica solution.

from random import*;printimport*;s=0;j=randrange
while int(gaussj(0,8**711):s=s*11+j(11)
print s/2^s%-2

DemonstrationIt is trivial to check that the while loop in the middle can generate all integers (albeit biased towards zero). "11" is chosen such that there are roughly half of numbers exceeding 2×106. The final print code transforms the conditionsrange from nonnegative integers to all integers.


Older solution:

Python 2, 44 bytes

Based on the Mathematica solution.

>>>from frandom =import*;print [intint(gauss(0,8**7)) for _ in xrange(10**6)]
>>> sum(1.0 for x in f if x >= 1e6) / len(f)
0.31688
>>> sum(1.0 for x in f if x <= -1e6) / len(f)
0.316475
>>> max(f)
10119326
>>> min(f)
-10028865

Doesn't really work because Python's float has only finite precision.

Python 2, 44 bytes

Based on the Mathematica solution.

from random import*;print int(gauss(0,8**7))

Demonstration of the conditions:

>>> f = [int(gauss(0,8**7)) for _ in xrange(10**6)]
>>> sum(1.0 for x in f if x >= 1e6) / len(f)
0.31688
>>> sum(1.0 for x in f if x <= -1e6) / len(f)
0.316475
>>> max(f)
10119326
>>> min(f)
-10028865

Python 2, 75 bytes

from random import*;s=0;j=randrange
while j(11):s=s*11+j(11)
print s/2^s%-2

It is trivial to check that the while loop in the middle can generate all integers (albeit biased towards zero). "11" is chosen such that there are roughly half of numbers exceeding 2×106. The final print code transforms the range from nonnegative integers to all integers.


Older solution:

Python 2, 44 bytes

Based on the Mathematica solution.

from random import*;print int(gauss(0,8**7))

Doesn't really work because Python's float has only finite precision.

Post Deleted by kennytm
Source Link
kennytm
  • 7k
  • 19
  • 47
Loading