473,699 Members | 2,612 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with random number generator? (I'm a beginner)

2 New Member
Ok, so I just started learning python and I've made a simple random number generator already but now I want the user to define the range in which the number can be generated. This is what I have so far but I cant seem to figure out what to do for line 7. I'm guessing there's some way to convert rand1 and rand2 into integers.


Expand|Select|Wrap|Line Numbers
  1. #demonstrates user defined range of possible random numbers.
  2. import random
  3.  
  4. print ("\t\t\tWelcome th the Random # Generator v2.0")
  5.  
  6. range1 = input ("\nPlease give the preffered minimum for the random number: ")
  7. range2 = input ("Please give the preffered maximum for the random number: ")
  8.  
  9. num = random.rand (range1, range2)
  10.  
  11. print ("Your number is ", num)
  12.  
Here is the error I got.

Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "C:/Python32/programs/usedDEFrand.py", line 9, in <module>
  3.     num = random.rand (range1, range2)
  4. AttributeError: 'module' object has no attribute 'rand'
Aug 25 '12 #1
3 2608
bvdet
2,851 Recognized Expert Moderator Specialist
You are close.

Expand|Select|Wrap|Line Numbers
  1. >>> random.randint(12,120)
  2. 91
  3. >>> 
Aug 25 '12 #2
MattBrady
2 New Member
I was not looking for how to generate a random number within predefined range. im looking to get a user defined range.
Aug 26 '12 #3
zmbd
5,501 Recognized Expert Moderator Expert
http://docs.python.org/library/rando...#module-random
All that you want to know and so much more!

:)

-z
Aug 27 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2472
by: Aaron | last post by:
I need some help writing this function the function returns a list of random non-duplicate integers in a string, 1 parameter indicating the maximum range. string randGen(int maxRange) maxRange=1000 the output would be:
70
6253
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like using the high-order bits returned by rand() instead of the low-order bits, avoiding using rand() for anything that wants decently random numbers, not using rand() if you want more than approx. UINT_MAX total different sequences, and so on. So I...
5
3348
by: Peteroid | last post by:
I know how to use rand() to generate random POSITIVE-INTEGER numbers. But, I'd like to generate a random DOUBLE number in the range of 0.0 to 1.0 with resolution of a double (i.e., every possible double value in the range could come up with equal probability). I'd also like to be able to seed this generator (e.g., via the clock) so that the same sequence of random values don't come up every time. Anybody have an easy and fast...
1
1933
by: Wally | last post by:
I am after VB.net code for a random number generator that will generate 10 different numbers between 1 and 10 and put them into an array. For example I want the output to be something like 10,7,8,6,9,4,5,2,3,1. Can anyone provide me with the code? Thanks,
9
16761
by: L33VaNcL33F | last post by:
I like to make a javascript that generate random number from the range number within : (10016486 and 99999985). the number always + 22423 that begin from 10016486 and end at 99999985 Example random result from generate button : 10016486 + 22423 = 10038909 10038909 + 22423 = 10061332 and so on, maximum to 99999985 or if somebody can convert below c++ code to working javascript/html random number generator. #include <cstdlib> #include...
16
539
by: jason.cipriani | last post by:
I am looking for a random number generator implementation with the following requirements: - Thread-safe, re-entrant. - Produces consistently reproducible sequences of psuedo-random numbers given a seed. - Relatively uniform, does not have to be perfect. The application is not a security or statistics application, the quality of numbers is not a priority although a fairly uniform
4
14766
by: Lexicon | last post by:
Hello; Does anyone know a 64-bit integer generator for 32-bit machines that use long long or __int64 etc ?
3
4434
AccessQuestion
by: AccessQuestion | last post by:
So just a quick question; more out of curiosity than anything. I have a form in which I pop a random number into a text box. Eventually that number will be placed by a user using a scale, but I wanted to simulate that now. Anyway, I used this code: MyWeight = Int(1000 * Rnd()) I assumed that will give me a random number, however EVERY time I launch my form the random numbers are the same. First 'random number' is always 705, followed...
4
2085
by: jhernandy | last post by:
I have built a Table using HTML and would like to have a random number genereator, genereate numbers in each of the 5 boxes on the table with no duplicates between 1-50, I have a problem getting the numbers in each box on table, and creating no duplicate numbers - 3x5 square box <table width="199" height="290" border="1"> <tr> <td height="45"><div align="center"> <h2><strong>T</strong></h2> </div></td> ...
0
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9197
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9054
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8897
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7785
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6549
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3071
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.