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. -
#demonstrates user defined range of possible random numbers.
-
import random
-
-
print ("\t\t\tWelcome th the Random # Generator v2.0")
-
-
range1 = input ("\nPlease give the preffered minimum for the random number: ")
-
range2 = input ("Please give the preffered maximum for the random number: ")
-
-
num = random.rand (range1, range2)
-
-
print ("Your number is ", num)
-
Here is the error I got. - Traceback (most recent call last):
-
File "C:/Python32/programs/usedDEFrand.py", line 9, in <module>
-
num = random.rand (range1, range2)
-
AttributeError: 'module' object has no attribute 'rand'
3 2608 bvdet 2,851
Recognized Expert Moderator Specialist
You are close. - >>> random.randint(12,120)
-
91
-
>>>
I was not looking for how to generate a random number within predefined range. im looking to get a user defined range.
zmbd 5,501
Recognized Expert Moderator Expert Sign in to post your reply or Sign up for a free account.
Similar topics |
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:
|
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...
|
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...
|
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,
|
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...
| |
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
|
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 ?
|
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...
|
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>
...
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |