Can anyone please explain why the features appear RANDOMLY without even using libraries? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can anyone please explain why the features appear RANDOMLY without even using libraries?

https://code.sololearn.com/cUPiLjiT3viD/?ref=app

10th Mar 2021, 7:31 AM
Αλέξανδρος
Αλέξανδρος - avatar
11 Answers
+ 1
That's because of using set. def unique_values(attribute): return list(set(attribute)) The python Set's order of elements is undefined. Set is defined by use of hashing.. so it does not guarantee, the way elements are added.. Ex: see print(set({1,2,'a','b',3})) this output is may different each time.
10th Mar 2021, 12:29 PM
Jayakrishna 🇮🇳
+ 1
what are “features”? what is supposed to happen? since there is no error message, please clarify what is going wrong.
10th Mar 2021, 8:34 AM
Wilbur Jaywright
Wilbur Jaywright - avatar
+ 1
The problem is that the list named features appears its elements RANDOMLY and I didn't even use a library or a module for random. Just run the program 3-6 times and you'll see the difference.
10th Mar 2021, 9:26 AM
Αλέξανδρος
Αλέξανδρος - avatar
+ 1
ah, i see. this likely has to do with memory allocation in list conversion. i do not know for sure as the code looks rather complex
10th Mar 2021, 11:35 AM
Wilbur Jaywright
Wilbur Jaywright - avatar
+ 1
Thank you. Also I'll check if I can make my code less complex.
10th Mar 2021, 11:43 AM
Αλέξανδρος
Αλέξανδρος - avatar
+ 1
For dice, i think you can get same result because you use only numbers (same types) so may result same. Some times it may depend on values you added. So not fully useful.. list1 = [1,2,3] set(list1) #creates set([1, 2, 3]) list2 = [3,2,1] set(list2) # set([1, 2, 3]) Hope it helps ... You're welcome..
10th Mar 2021, 12:43 PM
Jayakrishna 🇮🇳
+ 1
that last post had code that is not broken up properly! it should be... list1 = [1, 2, 3] set(list1) #will be set([1, 2, 3]) but anyway, in terms of making dice using the memory access system sets, I strongly disrecommend this. It could be very confusing, and the continuous memory change of creating new sets to create re-randomized order would eventually be speed-killing. in the end, even though the random module takes up more ram than a set, it would actually cause less ram activity.
10th Mar 2021, 3:13 PM
Wilbur Jaywright
Wilbur Jaywright - avatar
+ 1
Wait, I thought the random module is using the system time, but if that's true, then I can make random methods in other (lower level) programming languages.(The Greek programming language "ΓΛΏΣΣΑ" for example).
10th Mar 2021, 5:25 PM
Αλέξανδρος
Αλέξανδρος - avatar
+ 1
that’s a bit of a separate question, but I’ll go ahead and give you a preview. Yes, the random module does use the system time, and you can probably implement the formula in whatever language. the python built-in random module, like other random modules, uses a formula to generate a sequence of non-repeating numbers given a starting seed. in other languages, a random module sometimes does not draw on the system clock by default, and the seed always defaults to zero. thus, as the random sequence starts out, it will always generate the same numbers from its start, but the sequence continues indefinitely without repeating. using the system clock is a way to get an actual random seed each time, since the user will start the program at an arbitrary moment. as a book put it, “don’t use the built-in random module if you’re planning on starting an online casino. if you really need random numbers, you can go to idontrememberthewebsite.org, which delivers numbers based on the truly random process of radioactive decay.“
10th Mar 2021, 5:35 PM
Wilbur Jaywright
Wilbur Jaywright - avatar
0
Okay, that's useful. At least I can make some kind of dice without using a single library or a module.
10th Mar 2021, 12:38 PM
Αλέξανδρος
Αλέξανδρος - avatar
0
Thank you. Also I think you're talking about the random.org.
10th Mar 2021, 5:46 PM
Αλέξανδρος
Αλέξανδρος - avatar