Jump to content

Stickler999

Members
  • Posts

    3
  • Joined

  • Last visited

Previous Fields

  • Languages
    English, Deutsch, Español

Profile Information

  • Location
    Munich
  • Interests
    coding, sailing, climbing

Stickler999's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. So, I implemented a small testcode and found out, that we both were wrong 😉 For two integers "min" and "max" (including both) I get a good eval distribution of integer random numbers with this function: Math.floor(Math.random()*(max+1)+min); Mozilla docs show a slightly different variant: Math.floor(Math.random() * (max - min + 1)) + min; which seams to give the same results. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
  2. I don't agree with you. E.g. you want "0" or "1" as random numbers. According to the example at the reference page it should work like this: console.log(Math.floor(Math.random()*1+0)); But the result is always "0". This code gives "0" or "1": console.log(Math.round(Math.random()*1+0)); I'm not clear if console.log(Math.floor(Math.random()*2+0)); gives a better "randomnes" for 0 oder 1? Any Mathematicians here?
  3. https://www.w3schools.com/jsref/jsref_random.asp There it says: But with .floor() the result "10" is very unlikely, isn't it? I would prefer .round() Math.round(Math.random()*10+1);
×
×
  • Create New...