Comments (6)
@Jerakin I'm closing this for now. If you are having a trouble, please let me know.
from defold-random.
As expected!
There is no number between min: 1 and max: 1, so what is the actual problem?
from defold-random.
I would expect it to return 1. A random number between 1 and 1 is 1. The same way a random number between 1 and 2 is 1 or 2.
Most random generators I have used (mainly python) have had the following behaviour.
rnd.range(1, 1) -> 1 always
rnd.range(1, 0) -> ValueError
# Meaning that
if min == max:
return min
if min > max:
return nil
The change to return nil is a breaking change :)
from defold-random.
I'll implement this, but my opinion is this not a good practice.
Trying to generate random number by using same value is pointless.
You can simply check your min and max by using if
as you wrote.
if min == max:
return minif min > max:
return nil
from defold-random.
It's for convenience, we noticed this because in our project we use rnd
to pick a random element from a table, the table always includes at least one.
With the previous behavior we had implemented this as return myTable[rnd.range(1, #myTable)]
. We have have now changed that to do.
if #myTable == 1:
return myTable[1]
else:
return myTable[rnd.range(1, #myTable)]
Which works, even though it's a lot uglier. I am fine with either but the breaking change caught us of guard.
from defold-random.
@Jerakin I was terribly busy for a couple of weeks, sorry.
I add this, could you please test it?
from defold-random.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from defold-random.