Random of 2?

edmunds

Senior Member
Dear all,

I have been using the code below successfully to get decent "random" results of 3:

Random3sub:
random w26
RandomOf3 = w26//3+1 'pick random route out of three
return

I also need a random number of two and the code below does not seem to generate anything else than one:

Random2sub:
random w25
RandomOf2 = w25//2+1 'pick random route out of two
return

I'm not good with these byte and word mathematics, so I don't really understand neither of the pieces of code above - copied them from somewhere. Can you help out, please?


Thank you for your time,

Edmunds
 

eggdweather

Senior Member
get a random number, put it in word26, then divide it by 2 taking only the remainder then add 1 should give a random result eventually. That's how I read the code. Though I'm thinking if // is the remainder of a division, can't remember. Why it always give a result of 1 is not clear.
 

hippy

Technical Support
Staff member
Random of 2 works for me on a physical 28X2 and when simulation in PE5 and PE6, so there is perhaps something elsewhere which is altering 'w25' causing it to always deliver a 1 result.
 

edmunds

Senior Member
get a random number, put it in word26, then divide it by 2 taking only the remainder then add 1 should give a random result eventually. That's how I read the code. Though I'm thinking if // is the remainder of a division, can't remember. Why it always give a result of 1 is not clear.
Well, ok, maybe I'm not that bad at it then :). Because this is how I read it as well but got confused about one working and the other one not. I'll keep trying, but for now I cannot find anything wrong with it. W25 is not used anywhere not in its own form and not as b50 or b51. And I cannot see why and how would Sertxd (#RandomOf2) deceive me since Sertxd (#RandomOf3) performs as expected.


Thank you all for your input,

Edmunds
 

edmunds

Senior Member
Hippy,

My bad. w25 was used elsewhere. This is what you get if you confuse using Symbol thingy and variable codes which I don't anymore, but this must have been slipped due to copying form some older code. All is good now, no need to waste any more time on this.


Thank you once again,

Edmunds
 
Top