Ask coding questions

← Back to all posts
Does anyone know a js package to produce random numbers?
h
JULIODIAZ1 (46)

Ive tried using

Math.floor(Math.random() * 4);

to produce a number 0-3 but it cant be used repeatedly to produce more numbers so thats why i need a js package.

Answered by Coder100 (16970) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (16970)

Yes it can.

for (let i = 0; i < 100; i++) console.log(Math.floor(Math.random() * 4));


let val = Math.floor(Math.random() * 4);
console.log(val);

you should be asking to use less packages than blatantly not even trying smh

JULIODIAZ1 (46)

well I did search stack overflow but found nothing so @Coder100

xxpertHacker (855)

You do not need a package for literally every single thing.

What you need are functions and to just learn JavaScript.

realTronsi (906)

@xxpertHacker how's japanese? Also you have 8 months left >:0

xxpertHacker (855)

@realTronsi Haven't started, probably won't.

Damn, 8 months!? I'll be done well before then.

realTronsi (906)

@xxpertHacker idk maybe 7 months, also wdym done by then. Are you building a nuclear missile or something

xxpertHacker (855)

@realTronsi Ohh, I was just gonna go out suicide bomber style w/ the nuke, missiles are way more complicated, and require a launching mechanism, guidance system/mechanism, etc, but I'm too lazy for all of that.

realTronsi (906)

@xxpertHacker nuclear bombs are quite heavy, you sure you can lift that? Besides just use a random library, libraries exist for everything

#include <manhattanp.hpp>

#define XXPERTHACKERADDRESS {0.01100111011011110110111101100100, 0.1101100011101010110001101101011 }

int main(){
  struct target {
    double lat;
    double lon;
  }
  target xxpert_hacker = XXPERTHACKERADDRESS;
  bomb.init(xxpert_hacker);
  while(1){
    bomb.updatepos();
    if(bomb.exploded == 1) break;
  }
  std::cout << "gg";
  return 0;
}

also I don't write C++ so rip to syntax

EDIT: should've made bomb a class but whatever

xxpertHacker (855)

@realTronsi Whoa, I'm not trying to destroy more than 5 miles, it can't be so heavy that it wouldn't fit into the trunk of an average car.

Also, I thought about using the Manhatten Project C++ library, but it was pre-C++11, and all C++ libraries from before C++17 are awful... I've learned this from experience.

Regarding your example, the C-preprocessor became obsolete as of C++20, thankfully. And I'd probably use

constexpr auto XXPERTHACKER_ADDRESS = target {
 
  .latitude = 0.01100111011011110110111101100100,
 
  .longitude = 0.1101100011101010110001101101011
};

But let's not talk about terrorism on Repl, like c'mon

realTronsi (906)

@xxpertHacker you brought up suicide bombing, while nuclear bombs aren't necessarily terrorism

How about quasar.cpp? It's a pretty new lib, just init a 10^e-9 planck length quasar and it should take out about a mile radius sphere, perfect for your purpose. The aftershock from the collapse might span a few thousand miles but that damage should be minimal. A few million shattered ear drums should be all.

xxpertHacker (855)

@realTronsi pretty damn sure that unprovoked atomic bomb detonation would be classified as terrorism, not an act of war. Actually, I think possession of an atomic bomb by non-military personnel (civilian) is enough to be arrested in any country.

Oh, haven't heard of that library, sounds interesting, I'll check it out! Do they have a GitHub or something? Can you link their site or library download and setup instructions?

JULIODIAZ1 (46)

WHAT WHAT TF IS GOING ON IN MY POST @xxpertHacker

xxpertHacker (855)

@JULIODIAZ1 Nothing, it ended some time ago.

realTronsi (906)

@xxpertHacker actually I colonized Kepler-452b so I am entitled to a nuclear arsenal. Anyways what u up to?

xxpertHacker (855)

@realTronsi Bored af, came back to Repl because I had nothing to do. Would've been fun to see COVID drop people like the Bubonic plague or something, but no, it had to be lame, and just shut down stores and screw w/ the economy.

Besides that, I came back to finish two tutorials that I was working on: a JavaScript multi-threading + asynchrony tutorial and a raw WebAssembly tutorial.

Why? Because I don't have much else to do.

realTronsi (906)

@xxpertHacker bruh, anyways we could get back to making that virus if you want once I finish a dumb school project (too lazy to figure out why its jittering when you drag around the camera rn https://playneengine.realtronsi.repl.co/)

xxpertHacker (855)

@realTronsi Umm... if anything, let's discuss elsewhere, I'm not sure if OP will be okay this continued conversation.

xxpertHacker (855)

@realTronsi https://www.acronymfinder.com/Slang/OP.html

And yes, that super secret Repl, that I quite frankly forgot existed.

realTronsi (906)

@xxpertHacker ah okay, also why did you leave the moment you joined

Bookie0 (5969)

Check this out. You can put it in a function, and call it each time you need a random number.
:)

JULIODIAZ1 (46)

oh wait i dont think will work coz i need to have the output of it to be a variable @Bookie0

Bookie0 (5969)

@JULIODIAZ1 instead of using return, you can make a variable that contains that random number in the function

JULIODIAZ1 (46)

i got it fixed turns out it wasnt the number genrator that made my thing not work sorry! @Bookie0