I have to write a code for generating random numbers without using random module and its function.
How do I do it? I tried using the system time as it keeps on changing (importing milli seconds) but with tht I am able to get random nos in the range of thousand only.
sanchitgarg
0
Newbie Poster
Recommended Answers
Jump to PostI have to write a code for generating random numbers without using random module and its function.
How do I do it? I tried using the system time as it keeps on changing (importing milli seconds) but with tht I am able to get random nos in the range of …
Jump to PostA time based random number generator will only work if called once, or uses the random time between a user input event.
The function time.time() only updates 18.2 times per second, too slow if you request several random numbers quickly.
Jump to PostYou mean output sort of this
132434454545435435L
.Well this happens when the number gets greater than usual integer type range. Python converts normal integer into Long type and Python shows L after long types. When you do
print num
, L doesnt shows up.
Jump to PostWhat I mean is instead of directly printing whole list, you have to print numbers individually, to avoid L at end:
for x in rand_num: print x
Jump to PostWell there are several algorithms to generate random number, simplest to my knowledge being Linear congruential generator(LCG).
The general formula for LCG is X_{n+1} = \left( a X_n + c \right)~~\bmod~~m . The …
All 17 Replies
GreenDay2001
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
sanchitgarg
0
Newbie Poster
sanchitgarg
0
Newbie Poster
GreenDay2001
sanchitgarg
0
Newbie Poster
GreenDay2001
sanchitgarg
0
Newbie Poster
ov3rcl0ck
25
Junior Poster
sanchitgarg
0
Newbie Poster
GreenDay2001
sanchitgarg
0
Newbie Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
ov3rcl0ck
25
Junior Poster
sanchitgarg
0
Newbie Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
sanchitgarg
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.