Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
HFX
Nov 29, 2004

Brain Candy posted:

Unless you are using large lists (say 20000+), an ArrayList will be faster and allows constant time random access. If you only need to use the Deque interface, why not just use an ArrayDeque? Hell, if you only use List for iteration, just use Collection.

The list I work on are often on the order of a couple million at a time.

For the most part, either works just as well and you shouldn't really care which one you are using. If I'm needing random access, there are much better structures that I can both iterate through and give me random access to the data inside (Map). The place where it will matter is when you are performance tuning in which case access patterns and benchmarking must be considered.

You do bring a good point about Collection though. In general, always try to use the most general data structure you can for declaring your variables. Why declare an ArrayList list = new ArrayList() when if all you need is the List interface you can declare List list = new ArrayList(). If you later decide you need a different List, then you can just change the instantiation.

Adbot
ADBOT LOVES YOU

Brain Candy
May 18, 2006

Hmm, that is a little unclear. Second time's the charm : if you only use the List interface for .iterator() you could just store/pass/return things as Collections or Iterables instead.

edit: ^^^ ha, apparently I wasn't completely unintelligible

Brain Candy
May 18, 2006

The problem I see with linked list is that for any non-trivially sized list

code:
for(int i = 0; i < list.size(); ++i)
{
  T t = list.get(i);
  //...
}
performs very differently depending on the type of the list, something I really shouldn't need to know. Granted, my sample should be replaced with for-each, but similar problems come up for set(int, T) and sorting operations.

You can tell that is a design problem by the fact that the Collections API has instanceof checks for a RandomAccess marker interface buried in its guts.

Fly
Nov 3, 2002

moral compass

Brain Candy posted:

Hmm, that is a little unclear. Second time's the charm : if you only use the List interface for .iterator() you could just store/pass/return things as Collections or Iterables instead.

edit: ^^^ ha, apparently I wasn't completely unintelligible
Yes, I agree entirely then. :)

HFX
Nov 29, 2004

Brain Candy posted:

The problem I see with linked list is that for any non-trivially sized list

code:
for(int i = 0; i < list.size(); ++i)
{
  T t = list.get(i);
  //...
}
performs very differently depending on the type of the list, something I really shouldn't need to know. Granted, my sample should be replaced with for-each, but similar problems come up for set(int, T) and sorting operations.

You can tell that is a design problem by the fact that the Collections API has instanceof checks for a RandomAccess marker interface buried in its guts.

Insertions can cost just as bad on an ArrayList. This is why you use Iterators though. LinkedList make a lot of sense if your insertions are on heads or tails. Like I said before, it really all depends. We are splitting hairs here.

HFX fucked around with this message at 07:29 on Nov 11, 2009

Brain Candy
May 18, 2006

Linked list makes a lot of sense if your insertions are heads or tails, but hey it's a Deque. What I'm saying is that a linked list, despite its name, is crappy as a List.

Parantumaton
Jan 29, 2009


The OnLy ThInG
i LoVe MoRe
ThAn ChUgGiNg SeMeN
iS gEtTiNg PaId To Be A
sOcIaL MeDiA sHiLl
FoR mIcRoSoFt
AnD nOkIa
Since we're talking 'bout Lists, which one could be considered best in performance when passed to Collections.sort(list, comparator)? I know there isn't a one clear answer, but I know that some implementations most likely are worse than others for various technical reasons I haven't yet familiarized myself with.

To be specific, the reason I'm asking is that I need to sort a list containing about several hundred objects. The related comparison math is rather heavy and overcomplicated and while I can cache parts of it manually, it can't be cached fully because the comparison object alters the the result itself significantly; it's not just "is x bigger than y?" comparison.

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.
You want a data structure with O(1) time for element retrieval and assignment (for arbitrary indexes), which would be an ArrayList.

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

Parantumaton posted:

Since we're talking 'bout Lists, which one could be considered best in performance when passed to Collections.sort(list, comparator)? I know there isn't a one clear answer, but I know that some implementations most likely are worse than others for various technical reasons I haven't yet familiarized myself with.

To be specific, the reason I'm asking is that I need to sort a list containing about several hundred objects. The related comparison math is rather heavy and overcomplicated and while I can cache parts of it manually, it can't be cached fully because the comparison object alters the the result itself significantly; it's not just "is x bigger than y?" comparison.

quote:

The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed n log(n) performance. The specified list must be modifiable, but need not be resizable. This implementation dumps the specified list into an array, sorts the array, and iterates over the list resetting each element from the corresponding position in the array. This avoids the n2 log(n) performance that would result from attempting to sort a linked list in place.

In other words, it doesn't matter as far as algorithic complexity goes, but you'll pretty much always want to prefer an array list unless you actually need constant time middle insertion/removal or splicing (I'm not sure if Java's LinkedList even supports this)

sd6
Jan 14, 2008

This has all been posted before, and it will all be posted again
Quick question, how do I change the header of an HTTP GET request in a Java program (using something like HttpURLConnection) to accept JSON data?

Fly
Nov 3, 2002

moral compass

Parantumaton posted:

To be specific, the reason I'm asking is that I need to sort a list containing about several hundred objects. The related comparison math is rather heavy and overcomplicated and while I can cache parts of it manually, it can't be cached fully because the comparison object alters the the result itself significantly; it's not just "is x bigger than y?" comparison.
Do you mean the comparator, when you write "the comparison object"? Are you saying the act of compare(o1, o2) modified o1 or o2 in a way other than, say, lazy-loading contained objects from persistence?

covener
Jan 10, 2004

You know, for kids!

fge posted:

Quick question, how do I change the header of an HTTP GET request in a Java program (using something like HttpURLConnection) to accept JSON data?

See the inherited (agnostic) addRequestProperty() to add a HTTP header. I've always used commons-httpclient though.

sd6
Jan 14, 2008

This has all been posted before, and it will all be posted again

covener posted:

See the inherited (agnostic) addRequestProperty() to add a HTTP header. I've always used commons-httpclient though.

Awesome addRequestProperty works perfectly, thanks!

Parantumaton
Jan 29, 2009


The OnLy ThInG
i LoVe MoRe
ThAn ChUgGiNg SeMeN
iS gEtTiNg PaId To Be A
sOcIaL MeDiA sHiLl
FoR mIcRoSoFt
AnD nOkIa

Fly posted:

Do you mean the comparator, when you write "the comparison object"? Are you saying the act of compare(o1, o2) modified o1 or o2 in a way other than, say, lazy-loading contained objects from persistence?

Yes, it's part of a really finicky and code-smellish set relevance comparison.

Fly
Nov 3, 2002

moral compass

Parantumaton posted:

Yes, it's part of a really finicky and code-smellish set relevance comparison.
If your comparator changes the result of the next call of the comparator on the same objects, then the Java sorting methods probably won't work at all.

wintermuteCF
Dec 9, 2006

LIEK HAI2U!
Cannot javac/compile from command line in user folder.

Folder where I'm writing stuff: C:\user\username\java
Javac is installed in folder: C:\program files\java\jdk1.6.0_17\bin

I'm in the command line, and have this:
code:
C:\Users\username\Java>javac HelloApp.java
And it throws up this error:
code:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/Main
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.Main
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: com.sun.tools.javac.Main.  Program will exit.
Now, the book from which I'm learning Java says I need to add the JDK bin folder to the Path variable in System/Advanced/Environment Variables/System, and I've done so. Google searches say I need to add something to Classpath, and I'm pretty sure I've done that too. Here's what the entries for those two look like.

code:
System Variables:
CLASSPATH: c:\program files\java\jdk1.6.0_17\lib;c:\program files\java\jdk1.6.0_17\bin;C:\Program Files (x86)\QuickTime\QTSystem\QTJava.zip

Path: c:\program files\java\jdk1.6.0_17\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\
The OS is Windows 7, if it makes a difference. Thank you.

Fly
Nov 3, 2002

moral compass

wintermuteCF posted:

code:
System Variables:
CLASSPATH: c:\program files\java\jdk1.6.0_17\lib;c:\program files\java\jdk1.6.0_17\bin;
C:\Program Files (x86)\QuickTime\QTSystem\QTJava.zip
Javac generally does not need the jdk jar files in it's classpath, and I don't think setting the classpath to the directory where the jar files are will help at all.

If you change your classpath only to include the QTJava.zip file, does that help?

wintermuteCF
Dec 9, 2006

LIEK HAI2U!

Fly posted:

Javac generally does not need the jdk jar files in it's classpath, and I don't think setting the classpath to the directory where the jar files are will help at all.

If you change your classpath only to include the QTJava.zip file, does that help?

Actually fixed it with some help from a friend at work. Just added ;. to the end of the classpath entry and it works now.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Compiling from the command line is loving annoying. I suggest you use an IDE or learn to use Ant/Maven to do your compiling for you.

Fly
Nov 3, 2002

moral compass

MEAT TREAT posted:

Compiling from the command line is loving annoying. I suggest you use an IDE or learn to use Ant/Maven to do your compiling for you.
Are you suggesting this for the HelloApp.java issue above?

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
LOL no, but it only gets worse as your project grows in size and I feel it's valuable to learn it sooner rather than when you really need it and are pressed for time.

Parantumaton
Jan 29, 2009


The OnLy ThInG
i LoVe MoRe
ThAn ChUgGiNg SeMeN
iS gEtTiNg PaId To Be A
sOcIaL MeDiA sHiLl
FoR mIcRoSoFt
AnD nOkIa
Maven, however, doesn't improve your build quality at all, it's like sticking ice picks into your eyes. You're better off making reusable Ant scripts and using Ivy for dependency management.

geeves
Sep 16, 2004

Parantumaton posted:

Maven, however, doesn't improve your build quality at all, it's like sticking ice picks into your eyes. You're better off making reusable Ant scripts and using Ivy for dependency management.

Everyone seems to be torn (well not torn on opposite ends) on this , myself included. My old job moved from custom Ant scripts to Maven. Never really noticed any major issues except that we had several POMs per project and if one was out of sync, build would fail. Over all I like Maven and I like that Maven is pretty simple to setup and use from the start, but some things still trip me up and online help / documentation doesn't seem to cover it.

My main issue with Maven: it's either all or nothing with including dependencies. I can't just add what's needed. This is especially frustrating since I work with OSGI and it's easier to include dependent jars in the build jar instead of going through the hassle of Bundle-ing them or hacking them to pieces ( had to do this with Apache POI) but that's another thread.

geeves fucked around with this message at 06:15 on Nov 19, 2009

geeves
Sep 16, 2004

Actually, based on my last post I have a question:

Is it bad form to hack apart and repackage Jar files, especially those from Maven repos?

I work with OSGI, so it's a bit of a pain and here's why:

We need Apache POI for dealing with Excel documents (we dont' need POI, but it's super easy to work with and we're only reading before passing data onto the JCR).

But when loading into OSGI we need 2 jars: poi-3.x-FINAL and poi-ooxml-3.x-FINAL

Basically to instantiate the code it's:

Workbook wb = WorkbookFactory.create(InputStream in);

Well, WorkbookFactory is in poi-ooxml and Workbook is in poi-3.x yet they're in the same location / package (org.apache.poi.ss.usermodel)

OSGI will only load the classes of the package of the jar that's loaded first. So if I load poi-3.x first WorkbookFactory is not seen (even if it's in the MANIFEST) or if I load poi-ooxml first, Workbook (and other classes in poi-3.x) won't be seen or available.

I get this as a fail-safe.

To get POI to work, I had to extract the jars, move WorkbookFactory into poi instead of poi-ooxml (it was the only class in that package in poi-ooxml) then re-jar the classes, create bundles using Bnd (http://www.aqute.biz/Code/Bnd) and upload them to my OSGI manager.

It works. I couldn't be happier.

But, is this retarded or stupid? Is there a better way? Related to the above issue that, for me, Maven has been an all or nothing build with my dependencies (many of which are already loaded into the OSGI repo that I'm using). Hence why I had to find an alternative to include 3rd-party packages.

On the final note: I really like OSGI - it's saved lots of time in restarting the webserver as well as giving an immediate rundown on what's working or what's not because of a dependcy missing. But some things are a bit of a pain that could be solved in other stages of development.

Publius_Maximus
Apr 8, 2009
Alright folks, I really don't know about your policy on helping with assignments, but I've recently had a personal crisis I won't go into now, and I missed a few of my classes. I have an assignment due tomorrow, but I'm unsure on what exactly is going on. I'm a bit of a programming noob and missing those classes kind of hurt things. Well this assignment is due tomorrow, and I'm having a hard time STARTING it. So I am requesting specific help with the first thing I have to do, once that happens, I think I can handle the rest.

Anyway... here are my instructions.

"The book defines the Node class within the Binarytree class. Move the Node class into its own public definition inside Node.java. Add/remove import statements as needed.

3. Add the following static attribute to the BinaryTree class and the Node class:

private static final long serialVersionUID = 1L;

4. (10 pts) Write a static method named ex1() that returns a BinaryTree object representing the expression (2 + 4) * 8"

Once I have an example for how to do number 4, I think I can handle the rest of the code, but I'm just having issues getting things working from the start.

Anyway, the code I'm working with is here, the driver is at the bottom of the code. Can anyone give me some advice/help me out in any way?

http://pastebin.com/m2edfc556

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

Publius_Maximus posted:

4. (10 pts) Write a static method named ex1() that returns a BinaryTree object representing the expression (2 + 4) * 8"

Once I have an example for how to do number 4, I think I can handle the rest of the code, but I'm just having issues getting things working from the start.

Anyway, the code I'm working with is here, the driver is at the bottom of the code. Can anyone give me some advice/help me out in any way?

http://pastebin.com/m2edfc556

Do you know what the binary tree for that expression should look like? If you know that, it should be trivial.

Publius_Maximus
Apr 8, 2009
I don't know much about trees at all, this is the first time I've had to code one, if I saw a sample of something like that, I'd be able to expand on that base for the rest of the code.

RichardA
Sep 1, 2006
.
Dinosaur Gum
I've never been taught about trees so take this with a grain of salt.

A binary tree is made up of Nodes which are either null or contains a piece of data and references to two other binary trees. A Node which has both references null is known as a leaf.

An example of a expression tree for a+(b*c) is:
code:
     +
    / \
   a   *
      / \
     b   c
note that a,b,c all have two null references. To evaluate this tree start at the root and check if the data it contains is a value or an operator. If it contains a value return it else apply the operator to the result of evaluating the child nodes. In this case:
(value of evaluating left child) + (value of evaluating right child)
v.o.e left child = a
v.o.e right child = ((v.o.e *'s left child) * (v.o.e *'s right child))
v.o.e right child = (b*c)
Which leads to a+(b*c)

To make a similar representation for (2 + 4) * 8 with the code you posted you will need to construct a class which can contain either an int or an operator.

Edit: Or just use a char if you don't need to write code to evaluate it.

RichardA fucked around with this message at 10:06 on Nov 19, 2009

Publius_Maximus
Apr 8, 2009
Sorry guys I should have specified, I appreciate the help so far, but what I'm looking for is what the code itself looks like. I kind of understand the concept, but I have no knowledge of the syntax to put it in.

yatagan
Aug 31, 2009

by Ozma

Publius_Maximus posted:

Sorry guys I should have specified, I appreciate the help so far, but what I'm looking for is what the code itself looks like. I kind of understand the concept, but I have no knowledge of the syntax to put it in.


code:
BinaryTree a = new BinaryTree("a", null, null);
BinaryTree b = new BinaryTree("b", null, null);
BinaryTree c = new BinaryTree("b", null, null);
BinaryTree b_c = new BinaryTree("*", b, c);
BinaryTree a_b_c = new BinaryTree("+", a, b_c);
Condensed version:

code:
BinaryTree a_b_c = new BinaryTree("+", new BinaryTree("a", null, null), new BinaryTree("*", new BinaryTree("b", null, null), new BinaryTree("c", null, null)));

Parantumaton
Jan 29, 2009


The OnLy ThInG
i LoVe MoRe
ThAn ChUgGiNg SeMeN
iS gEtTiNg PaId To Be A
sOcIaL MeDiA sHiLl
FoR mIcRoSoFt
AnD nOkIa

geeves posted:

Is there a better way?

Since I already expressed my hate towards Maven, I feel I now have to show you the alternative, which for dependency management is Apache Ivy (part of Ant project).

The way Ivy handles dependencies is through configurations which there can be as many for every individual project as you like. Basically your very simplest Ivy dependency file could look like this:

code:
<ivy-module version="1.0">
    <info organisation="org.mycompany" module="my-product"/>
    <configurations>
        <conf name="test" description="testing dependencies"/>
    </configurations>
    <dependencies>
        <dependency org="junit" name="junit" rev="3.8+" conf="test->default"/>
    </dependencies>
</ivy-module>
What this means is that when you use Ivy with the test configuration selected, JUnit 3.8 or newest available one that doesn't conflict with other required dependencies is added to your classpath. Yes, that means that if another dependency -or even transitive dependency which is a dependency for some other dependency- defines that it must be JUnit 4.3 exactly, then that's what you'll get.

The test->default part should be read as "my-product's test configuration depends on junit 3.8+'s default configuration". There's of course some default confs I didn't add there, namely default, runtime, compile and master each with their own predefined purpose such as that master is meant for acquiring the immediate result of the org/name resolving, ie. actual product without any of its dependencies.

At this point I do want to point out that Ivy has both Ant tasks readily available and great Eclipse plugin called IvyDE for testing and making configurations and dependencies so it's no hassle at all to make even complex combinations; one important feature of the configurations is that they can extend each other, just add extends="anotherconf" attribute to the <conf> element.

So, with what you're asking you have the following environments for your project:

default - All the normal dependencies you may have within your project.
OSGi - All the additional OSGi related dependencies plus the ones from default.

In Ivy terms, this would be something like so:

code:
<ivy-module version="1.0">
    <info organisation="org.mycompany" module="my-product"/>
    <configurations>
        <conf name="default" extends="runtime" description="Default dependencies for My-Product" />
        <conf name="runtime" description="Dependencies needed only for runtime" />
        <conf name="compile" extends="default" description="Compile time dependencies" />
        <conf name="osgi" extends="default" description="Additional OSGi dependencies" />
        <conf name="test" extends="compile" description="testing dependencies"/>
    </configurations>
    <dependencies>
        <!-- Special OSGi dependencies -->
        <dependency org="org.apache.poi" name="poi-ooxml" rev="3.5+" conf="osgi->runtime"/>

        <!-- Default dependencies below -->
        <dependency org="org.apache.poi" name="poi" rev="3.5+" conf="compile,runtime->default"/>
        <dependency org="other" name="libraries" rev="latest.integration" conf="runtime->default"/>

        <!-- We like to test our software -->
        <dependency org="junit" name="junit" rev="3.8+" conf="test->default"/>
    </dependencies>
</ivy-module>
I added some other configurations just for the sake of it.

Basically now you can make reusable Ant scripts which do stuff such as "get test dependencies and sources from src and test root folders, run all tests, if they pass, run coverage and other statistics and finally build JAR/WAR (don't forget automated MANIFEST.MF!) and deploy it to my own private Ivy repository".

Mix all the above with a continous integration environment such as Hudson and you can take that even further; "After the My-Product has been succesfully built, automatically build both default and OSGi deployment packages, deploy those to Server D and Server O and run a set of integration tests on both of them". Best part of CI? You can configure it so that whenever you commit code to your source repository of choice, all of this is done automatically.

Sure, making the Ant tasks takes some time but once they're done, they do exactly what you want and if you make them with a bit of a thought, you can reuse them so that you end up with a library of premade Ant targets which you can copy-and-paste, mix and match to create new build.xml:s for your project. Personally I love this way of dependency management and thus I just can't even look at Maven's equivalent anymore.


PS. I have an eye infection so if there's any proof reading issues with this post, please buy me antibiotics.

HFX
Nov 29, 2004
Right now I'm writing a servlet to test something at work.

The input is coming from a device which is using xoring a string twice using two keys.

The result is: .$8:2<!
I've verified Java and the box are both giving me the same result when doing it byte by byte.

My problem is when reading the http header, that the device must be reEncoding to another format as it is sending me: 8%11%0B%02%0B%1EK%11%16K+%17%08%17%00%1B%11.
This immediately looks like some kind of encoding, however, I am not sure what the encoding actually is. Anyone recognize this by the off chance and know how I would decode it in java so I can run the xoring to reverse it?

yatagan
Aug 31, 2009

by Ozma

HFX posted:

Right now I'm writing a servlet to test something at work.

The input is coming from a device which is using xoring a string twice using two keys.

The result is: .$8:2<!
I've verified Java and the box are both giving me the same result when doing it byte by byte.

My problem is when reading the http header, that the device must be reEncoding to another format as it is sending me: 8%11%0B%02%0B%1EK%11%16K+%17%08%17%00%1B%11.
This immediately looks like some kind of encoding, however, I am not sure what the encoding actually is. Anyone recognize this by the off chance and know how I would decode it in java so I can run the xoring to reverse it?

URL encoding. http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLDecoder.html

HFX
Nov 29, 2004

Sadly tried that but it does not match the string generated by the xoring.

yatagan
Aug 31, 2009

by Ozma

HFX posted:

Sadly tried that but it does not match the string generated by the xoring.

Post your code, and the code of the generator.

FateFree
Nov 14, 2003

How do i generate a random long from 1-7 billion, when there is no range function like there is with integer?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

FateFree posted:

How do i generate a random long from 1-7 billion, when there is no range function like there is with integer?

If it doesn't need to be cryptographically secure then you can use the same method they use in Random.nextInt(int n). In the javadoc they go over it:

All n possible int values are produced with (approximately) equal probability. The method nextInt(int n) is implemented by class Random as if by:
code:
 public int nextInt(int n) {
   if (n <= 0)
     throw new IllegalArgumentException("n must be positive");

   if ((n & -n) == n)  // i.e., n is a power of 2
     return (int)((n * (long)next(31)) >> 31);

   int bits, val;
   do {
       bits = next(31);
       val = bits % n;
   } while (bits - val + (n-1) < 0);
   return val;
 }
read the javadoc for caveats.

FateFree
Nov 14, 2003

Yes thats handy for ints, but I can't get a number over 2 billion that way. There is no corresponding long(long range) method in random, i imagine because the int version uses a long to catch overflows.

So I guess something special has to be done for my case but I'm not sure what it is.

Parantumaton
Jan 29, 2009


The OnLy ThInG
i LoVe MoRe
ThAn ChUgGiNg SeMeN
iS gEtTiNg PaId To Be A
sOcIaL MeDiA sHiLl
FoR mIcRoSoFt
AnD nOkIa
If your desired range is 1...7 billion and you can get to 2 billion, why not just do that one to three times, add those three together and then add another billion?

Adbot
ADBOT LOVES YOU

monads mo problems
Nov 27, 2007
There is probably a better way, but:
code:
public static long randomLong(long min, long max) {
        return Math.round((Math.random() * (max - min)) + min);
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply