Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
January 11th, 2013, 02:16 PM
 leykon121
Registered User

Join Date: Dec 2012
Posts: 6
Time spent in forums: 2 h 49 m 26 sec
Reputation Power: 0
Hom work Help (Random)

Hello i need a help

Quote:
 inum1=random.randrange(0,50) inum2=random.randrange(0,35) inum3=random.randrange(0,600)

how can i make that this code in loop evry time the numbers will be lower and lower and not gust diferent from each other in allot numbe?

#2
January 11th, 2013, 02:41 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,132
Time spent in forums: 1 Month 3 Weeks 2 Days 5 h 47 m 38 sec
Reputation Power: 455
Monte-Carlo simulation of some sort of situation.
Code:
```import random
L = []
while len(L) < 100:
(n, count,) = (9999, 0,)
while n:
count += 1
n = random.randrange(n)
L.append(count)

print('mean number of trials: %g'%(sum(L)/float(len(L))))```
__________________
[code]Code tags[/code] are essential for python code!

#3
January 11th, 2013, 02:52 PM
 leykon121
Registered User

Join Date: Dec 2012
Posts: 6
Time spent in forums: 2 h 49 m 26 sec
Reputation Power: 0
Quote:
 Originally Posted by b49P23TIvg Monte-Carlo simulation of some sort of situation. Code: ```import random L = [] while len(L) < 100: (n, count,) = (9999, 0,) while n: count += 1 n = random.randrange(n) L.append(count) print('mean number of trials: %g'%(sum(L)/float(len(L))))```

can you please make it more simple.
i cant use this simbols.

thank for helping

#4
January 11th, 2013, 03:11 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,132
Time spent in forums: 1 Month 3 Weeks 2 Days 5 h 47 m 38 sec
Reputation Power: 455
Code:
```import random

n = 99999                               # in allot numbe?

while n:                                # code in loop
print(n)
n = random.randrange(n)          # numbers will be lower and lower

print(n)  # (zero)```

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Hom work Help (Random)