Загрузка...

How to output a random number greater than a given variable?

Thread in Node.js created by Hollywood May 14, 2024. 185 views

  1. Hollywood
    Hollywood Topic starter May 14, 2024 э 20,032 Oct 28, 2020
    Code
    let N = Number(prompt())
    console.log(Math.round(Math.random() * N))
    console.log(Math.round(Math.random() ??? N))
    * - до этого числа
    ??? - что нужно сделать?
     
  2. Toil
    Toil May 14, 2024 ������� ������ :coder: 3543 Nov 18, 2018
    1. View previous comments (2)
    2. Hollywood Topic starter
      Toil, 
      Code
      Math.round(Math.random() + N)
      выдает число, на 1 больше, чем указано в переменной, других чисел не дает
    3. Hollywood Topic starter
      Toil, аа, понял. А без функции никак не получится сделать?
    4. Toil
      Hollywood,
      ⁡Math.floor(N + Math.random() * (1000 + 1 - N))
      ⁡можешь так сделать, но суть не поменяется (1000 - макс число). По другому вроде никак не сделать
    5. View the next comments (1)
Loading...
Top