Yesterday whilst working on a project I needed to generate randomly a -1 or a 1. I tried for some time to get it working and thought how stupid can I be. Finally I came up with this:
This was then to be used in the following line:
The result of the last part is a positive or negative number between 0 and 1.
Then it hit me, while writing this, why don't you combine the two (not tested):
Just as info. The application is to move the end point of a line by a small amount based on its length.
And my question: How to prevent 0?
B4X:
Dim RandomValue As Int=Rnd(1, 3)*-1
B4X:
If (center<>s) And (center<>e) Then boltarray(center)=(boltarray(e)+boltarray(s))/2 + Rnd(0,1)*actlevel*RandomValue
Then it hit me, while writing this, why don't you combine the two (not tested):
B4X:
If (center<>s) And (center<>e) Then boltarray(center)=(boltarray(e)+boltarray(s))/2 + Rnd(-1,1)*actlevel
Just as info. The application is to move the end point of a line by a small amount based on its length.
And my question: How to prevent 0?