is it possible to start the random generator with a startvalue so we can have the same rnd () on all devices ?
randomize (1999)
wlog rnd(100) - same bytesequenz on every devices .
thx
starting the randomize generator with a start value?
-
- Posts: 341
- Joined: Tue Jun 21, 2022 2:17 pm
- Location: South coast UK
- Has thanked: 178 times
- Been thanked: 110 times
Re: starting the randomize generator with a start value?
I too required this but could not find a way of doing it in Annex, so I wrote my own.
It produces a reasonably random 8 digit number between 0 and 1
The seed can be any 8 digit number to produce different sequences.
EDIT: Changed a few numbers to give a better sequence.
Code: [Local Link Removed for Guests]
Seed = 12345678
For N = 1 to 20
Gosub Random
Dice = Int(6*Rand+1)
wlog Rand,Dice
Next N
wait
Random:
Rand = (4.3*Seed+3.3e9) mod 1e8
Seed = Rand
Rand=Rand/1e8
Return
The seed can be any 8 digit number to produce different sequences.
EDIT: Changed a few numbers to give a better sequence.
- cicciocb
- Site Admin
- Posts: 1964
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 422 times
- Been thanked: 1310 times
- Contact:
Re: starting the randomize generator with a start value?
HI all,
looks this is an old post that I missed.
In fact I just re-discovered (I forgot to document) that it is possible to define the seed simply giving an initial negative number as argument of RND.
You can find a live example here
looks this is an old post that I missed.
In fact I just re-discovered (I forgot to document) that it is possible to define the seed simply giving an initial negative number as argument of RND.
You can find a live example here
-
- Posts: 341
- Joined: Tue Jun 21, 2022 2:17 pm
- Location: South coast UK
- Has thanked: 178 times
- Been thanked: 110 times
Re: starting the randomize generator with a start value?
rnd function not working for me with Annex32 BLE CAN 1.47.2 (at least, not as expected).
rnd(N) only returns a random float when N=1
Any -ve number returns only 0
Any number >1 only returns a random INTEGER between 0 and the value used.
Just tested with 1.44.2 with same results.
Also tried 1.44.2 on ESP2866. Same results.
Tried changing the values in the simulator to which you linked. Results totally erratic.
Not sure what is going on.
rnd(N) only returns a random float when N=1
Any -ve number returns only 0
Any number >1 only returns a random INTEGER between 0 and the value used.
Just tested with 1.44.2 with same results.
Also tried 1.44.2 on ESP2866. Same results.
Tried changing the values in the simulator to which you linked. Results totally erratic.
Not sure what is going on.
- cicciocb
- Site Admin
- Posts: 1964
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 422 times
- Been thanked: 1310 times
- Contact:
Re: starting the randomize generator with a start value?
HI Bernie,
don't know exactly what you are expecting from this function.
The doc says :
"
RND(number)
Returns a random number in the range from 0 to ‘number' -1
If ‘number’ is equal to 1, the result will be a value less than 1 but greater than or equal to zero.
"
I included this text for the next release of the help:
If ‘number’ is a negative number, it will be used as seed by the pseudo-random number generator algorithm. This will force a deterministic sequence.
The function works as expected, at least as per the documentation.
The result of the function used with a negative number has no meaning as it just set the seed for the next random sequence
don't know exactly what you are expecting from this function.
The doc says :
"
RND(number)
Returns a random number in the range from 0 to ‘number' -1
If ‘number’ is equal to 1, the result will be a value less than 1 but greater than or equal to zero.
"
I included this text for the next release of the help:
If ‘number’ is a negative number, it will be used as seed by the pseudo-random number generator algorithm. This will force a deterministic sequence.
The function works as expected, at least as per the documentation.
The result of the function used with a negative number has no meaning as it just set the seed for the next random sequence
-
- Posts: 341
- Joined: Tue Jun 21, 2022 2:17 pm
- Location: South coast UK
- Has thanked: 178 times
- Been thanked: 110 times
Re: starting the randomize generator with a start value?
I think I have miss-understood the use of rnd(-N)
From your last reply now I understand that rnd(-N) is used only once to set the seed for the next sequence.
Then use rnd(1) to produce a random number where 0 < RND <1
Use rnd(-1) again to repeat the sequence.
However;
rnd(10) produces INTEGER numbers between 0 and 10 (0<=rnd<10)
I was expecting FLOATS. This is not a problem, just not expected.
Sorry for my missunderstanding.
From your last reply now I understand that rnd(-N) is used only once to set the seed for the next sequence.
Then use rnd(1) to produce a random number where 0 < RND <1
Use rnd(-1) again to repeat the sequence.
However;
rnd(10) produces INTEGER numbers between 0 and 10 (0<=rnd<10)
I was expecting FLOATS. This is not a problem, just not expected.
Sorry for my missunderstanding.
-
- Posts: 142
- Joined: Mon Feb 08, 2021 10:10 pm
- Location: Scotland
- Has thanked: 46 times
- Been thanked: 50 times
Re: starting the randomize generator with a start value?
Yes - I met that earlier today and then used rnd(1) * 10 to get the required float values.rnd(10) produces INTEGER numbers between 0 and 10 (0<=rnd<10)
I was expecting FLOATS. This is not a problem, just not expected.