[Tutor] unittest with random population data

Sydney Shall s.shall at virginmedia.com
Tue Jun 2 12:59:11 CEST 2015


On 02/06/2015 07:59, Steven D'Aprano wrote:
> Please keep your replies on the tutor list, so that others may offer
> advice, and learn from your questions.
>
> Thanks,
>
> Steve
>
> On Mon, Jun 01, 2015 at 06:03:08PM +0100, Sydney Shall wrote:
>> On 31/05/2015 00:41, Steven D'Aprano wrote:
>>> On Sat, May 30, 2015 at 12:16:01PM +0100, Sydney Shall wrote:
>>>
>>>> I have written a unittest class which works OK.
>>>> But the problem I have is that because I use the random module to
>>>> populate my initial arrays, my data is not strictly predictable even
>>>> though I am using seed(0).
>>>
>>> Please show us how you populate your arrays, because what you describe
>>> sounds wrong. Seeding to the same value should give the same sequence of
>>> values:
>>>
>>> py> import random
>>> py> random.seed(0)
>>> py> a = [random.random() for i in range(10**6)]
>>> py> random.seed(0)
>>> py> b = [random.random() for i in range(10**6)]
>>> py> a == b
>>> True
>>>
>>>
>> Thank you for the advice Steven.
>> I was of course aware that I had to use random.seed(0), which I had
>> done. I was puzzled by the fact that it did not give me reprocibly
>> results, which it did when I was learning python. But because you drew
>> attention to the problem, I have looked at again. I surmised that
>> perhaps I had put the seed statement in the wrong place. I have tried
>> several places, but I always get the sam spread of results.
>>
>> Perhaps, to help get advice I should explain that I populate a a list thus:
>>   self.ucc = np.random.normal(self.mean_ucc, self.sigma_ucc, 200)
>> This does give me list of 200 slightly different numbers.
>> The mean_ucc is always 15.0 and the sigma value is always 3.75.
>> The actual mean and sigma of the random numbers is checked that it is
>> within 5.0% of 15.0 and 3.75 respectively.
>> Following your advice I did a little test. I repeated a little test
>> program that I have written, which gives me sensible and proper results.
>> I repeated the test 8 times and a then noted a useful output result.
>> When I plot the actual mean of the population used against the output
>> result I chose, I obtain a perfect straight line, which I should.
>>
>> Now I still think that I am using the random.seed(0) either incorrectly
>> or in the wrong place.
>> If there is any other information that might clarify my problem, I will
>> be grateful to be told.
>> I would be most grateful for any guidance you may have, indicating where
>> I should look for what I suspect is a beginner's error.
>>
>> --
>> Sydney
>>
>
Apolgies. I thought that I had dione so. I will be more careeful infuture.

-- 
Sydney


More information about the Tutor mailing list