+ 8

How to permanently store any random generated value?

I want to store it in somewhere so that It will return the previous random value(that I've stored) not the newly random value. Also, using any database like sqllite it will always generate a new value and store it. Same with Pickel module Any way for doing so?

1st Sep 2020, 3:46 AM
Arctic Fox
Arctic Fox - avatar
12 Respuestas
+ 4
𝙍𝙞𝙨𝙝𝙖𝙗𝙝 You can run this code in an IDE where there already exists file 'filename.txt' And it will keep on adding text as you run it https://code.sololearn.com/cZ66iKNMr7Nm/?ref=app
1st Sep 2020, 5:37 AM
Namit Jain
Namit Jain - avatar
+ 7
Nope, it will always give the new value that it will generate but what I want is: Whatever it generate at any time that also it stores again and shows the previous value Namit Jain Like: https://code.sololearn.com/cY830SXsz958/?ref=app Whatever value it will generate firstly I want to store it and print it then
1st Sep 2020, 4:00 AM
Arctic Fox
Arctic Fox - avatar
+ 6
Lothar I got the answer. Now, my turn to try. If you want to know where I would use it so,I want to use it in a code that will generate random numbers at running it different times, I'll need them when running the code second time and it will print it the number generated firstly. Printing it is enough for me. I hope I was clear!
1st Sep 2020, 12:08 PM
Arctic Fox
Arctic Fox - avatar
+ 5
Namit Jain I think I'm unable to explain you. Will you please give me an example so that I can tell you??
1st Sep 2020, 4:50 AM
Arctic Fox
Arctic Fox - avatar
+ 5
Namit Jain No output 😶
1st Sep 2020, 6:33 AM
Arctic Fox
Arctic Fox - avatar
+ 5
what are you planning to do with the "older / previous" values? Please try to describe it without caring about possible solution. When will you need them? in the same session? on a different day? And how should they be used or processed?
1st Sep 2020, 12:00 PM
Lothar
Lothar - avatar
+ 5
Namit Jain I've uploaded the file(an empty file)and copied it's link too but it's saying "No such file or directory"
1st Sep 2020, 1:13 PM
Arctic Fox
Arctic Fox - avatar
+ 3
generate the random variable, write it to a text file and save it. then when you want to access the random number, read the text file?
2nd Sep 2020, 12:07 PM
madeline
madeline - avatar
+ 2
Storing them in the files will help you!
1st Sep 2020, 3:49 AM
Namit Jain
Namit Jain - avatar
+ 2
𝙍𝙞𝙨𝙝𝙖𝙗𝙝 read the complete answer 😐
1st Sep 2020, 6:39 AM
Namit Jain
Namit Jain - avatar
+ 2
𝙍𝙞𝙨𝙝𝙖𝙗𝙝 ya same problem faced by me too! We will have to import some library that can accept online links! Try searching it on google! Something like urllib, http etc libraries should be used ig
1st Sep 2020, 2:31 PM
Namit Jain
Namit Jain - avatar
+ 1
𝙍𝙞𝙨𝙝𝙖𝙗𝙝 Use the append mode
1st Sep 2020, 4:01 AM
Namit Jain
Namit Jain - avatar