I did a card library in unity3d in c# and I did set the seed, but that's also optional there. Is good to know anyways, now I will keep an eye when doing random tests. Is always interesting how a trivial task in one language could be a pain in the butt in other languages.
public Shoe (int decks, int stopDeal, int seed)
{
_stopDeal = stopDeal;
_deal = 0;
_decks = decks;
_isLastShoeCard = false;
// Make a deck once
myDeck = new Deck ();
AddCardsToList (decks, myDeck, _unshuffledCards);
_shuffledCards = new List<Card> (_unshuffledCards);
_iterator = new Iterator (_shuffledCards);
_rng = new System.Random (seed);
}
About the seed, yes, "once again", python is "battery included". Effectively there are other language (someC version I believe, I don't remember which one) where you have to generte your own seed to get the randomness. In python, the seed is "randomly" generated for you.
Note: I didn't look at your code before so when I saw mentalplex talking about assinging the seed, I thought you used a constant value. So your approach is good too, actually. But not necessary with python, so. ;)
Noted. I am not an expert on python nor random numbers and you made me look this up. Always looking to hear the more experienced coders on this site, and improve on my coding :). Apparently do you not need to set the seed, because when the random object is initialized it sets the seed to the default param which is system time.
Random Class:
def __init__(self, x=None):
"""Initialize an instance.
Optional argument x controls seeding, as for Random.seed().
"""
self.seed(x)
self.gauss_next = None
def seed(self, a=None, version=2):
"""Initialize internal state from hashable object.
None or no argument seeds from current time or from an operating
system specific randomness source if available.
For version 2 (the default), all of the bits are used if *a* is a str,
bytes, or bytearray. For version 1, the hash() of *a* is used instead.
If *a* is an int, all bits are used.
"""
if a is None:
try:
# Seed with enough bytes to span the 19937 bit
# state space for the Mersenne Twister
a = int.from_bytes(_urandom(2500), 'big')
except NotImplementedError:
import time
a = int(time.time() * 256) # use fractional seconds
Either way I am surprised the initial python kata was approved it was generating basically blank random tests with "A" and 0 for the rule. If you look at the fork diff you can spot the issue. Initial fork was generating the next random floating point number in the range [0.0, 1.0). And not a random int within a range which is what the ultimate goal was.
Thanks. I guess it could be deleted. The main problem was that the random tests were blank. You can see a screenshot on the discourse kata page. I don't think the original fork knew how to generate random range. Easy fix. And not sure how many freebies went through with python.
Just debugging the random generation test code, and it is not working as intended. I ran the code on my computer and even with that fixed it is making the same test over and over. Feeding letter "a" as the text and rule for 0. I believe there might be an issue with the way you are using random.
Edit 1: Here's the for loop fixed, using randint: (Note: I think this is too easy for random tests since you are only using a-z letters, you could add other characters to the chars string for more consistency with the 0-255 ASCII)
for i in range(50):
text = ""
for j in range(random.randint(1, 41)):
text += chr(ord(chars[random.randint(0, len(chars) -1)]))
rule = random.randint(0, 450)
expected = encryptSol(text, rule)
self.assertEqual(encrypt(text,rule), expected)
If we make a concatenation of string is better to declare a "std::stringstream" instead of "std::string"?!?
Why?
I'm still getting the errors on 3, 5, 6, 7.
I did a card library in unity3d in c# and I did set the seed, but that's also optional there. Is good to know anyways, now I will keep an eye when doing random tests. Is always interesting how a trivial task in one language could be a pain in the butt in other languages.
About the seed, yes, "once again", python is "battery included". Effectively there are other language (someC version I believe, I don't remember which one) where you have to generte your own seed to get the randomness. In python, the seed is "randomly" generated for you.
Note: I didn't look at your code before so when I saw mentalplex talking about assinging the seed, I thought you used a constant value. So your approach is good too, actually. But not necessary with python, so. ;)
Noted. I am not an expert on python nor random numbers and you made me look this up. Always looking to hear the more experienced coders on this site, and improve on my coding :). Apparently do you not need to set the seed, because when the random object is initialized it sets the seed to the default param which is system time.
Random Class:
Either way I am surprised the initial python kata was approved it was generating basically blank random tests with "A" and 0 for the rule. If you look at the fork diff you can spot the issue. Initial fork was generating the next random floating point number in the range [0.0, 1.0). And not a random int within a range which is what the ultimate goal was.
the seed HAS to be random. Without it, the tests are no longer random! ;)
Thanks. I guess it could be deleted. The main problem was that the random tests were blank. You can see a screenshot on the discourse kata page. I don't think the original fork knew how to generate random range. Easy fix. And not sure how many freebies went through with python.
not sure why you're setting the seed, but approved nonetheless
Fixed Random Generation code. There were issues with random numbers generation.
Added more characters, initial fork was only using a-z.
Just debugging the random generation test code, and it is not working as intended. I ran the code on my computer and even with that fixed it is making the same test over and over. Feeding letter "a" as the text and rule for 0. I believe there might be an issue with the way you are using random.
Edit 1: Here's the for loop fixed, using randint: (Note: I think this is too easy for random tests since you are only using a-z letters, you could add other characters to the chars string for more consistency with the 0-255 ASCII)