Alejandro Barrero

Ranch Hand
+ Follow
since Aug 01, 2005
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Alejandro Barrero

I still don't understand why my old code was generating a huge number of duplicate random numbers

New code with an idea from Carey Brown works like a charm.
5 months ago
Thanks to Carey Brown. I changed the code in two simple ways

I am using the code to generate 20 arrays.

It is necessary to compare absolute values.

I only got three repetitions in three different arrays.
[1, -3, -2]
[-2, -9, 1]
[10, 2, 6]
qtyFilled=2 i=1 lookFor-4 count=0qtyFilled=2 i=0 lookFor7 count=0[-7, 4, -6]
[1, -4, -7]
[9, 7, -4]
[8, -2, -3]
[1, -3, 5]
[-2, -8, -6]
[-1, 4, 8]
qtyFilled=1 i=0 lookFor2 count=0[-2, 4, 8]
[9, -7, -5]
[-1, 4, 10]
[8, 4, 6]
[4, 5, -1]
[7, -9, -2]
qtyFilled=2 i=0 lookFor-1 count=0[-1, 3, 4]
[10, 3, 4]
[-7, 2, 5]
[-4, 9, 3]

Wonderful. The good news is that now I know how to do it; The bad news is that after so many analysis I still don't know what I was doing wrong; by to morrow I'll figure out my stupidity. Great thanks Carey Brown.
5 months ago
I respectfully disagree. You do say "We can see that you are creating three random numbers in line 6, but the comments don't tell us what you are trying to do overall." What I am trying to do overall is inmaterial, although the comment says clealy that I want to create an array of three int with absolute value from one to maximum.
You also say; "Why are you making the numbers negative before testing for duplicates? If you test for duplicates first, you won't need to use Math#abs()" I am making some of the numbers negative because I want to have the numbers negative with a 50% of probability. Yes, I could create three numbers at random and verify that they are not repeated; then I could loop over the array and change the numbers to negative with 50% probabilkty, but that is a waste of time. "Why have you got the strange syntax 1 + 1?" I am wrtimng 1 + 1 because anybody who anderstands the code of ThreadLocalRandom.current().nextInt() knows that the arguments are minimum, maximum + 1.
When you say "You are not putting random numbers into your array (not even pseudo-random)", you should know know that you cannot create random numbers in a computer (you need a physical process for tha;, you would know that you are wrong if you understood ThreadLocalRandom.current().nextInt() (it returns pseudo-random numbers).
I don't want to use streams and that's my choice; I am not asking for help to make my code better; I am asking for help to fing out why the random number generator is not working. At this point I am considering writing a method using The Linear Congruential Method from the book "The Art of Computing Programming volume I Fundamental Algorithms" by professor Donal E Knuth; I will post the results when I am done.
5 months ago
Thank you very much for your help. The commented code is

The program works correctly if the code that tests for repeated values is commented

To run the code I am using

I will be very happy to provide any further clarification.
5 months ago

Running  the program is printing large numbers of repeated values:
i=1 j=0 nextVariable=6 count=738377
i=1 j=0 nextVariable=6 count=738378
i=1 j=0 nextVariable=6 count=738379
i=1 j=0 nextVariable=6 count=738380
i=1 j=0 nextVariable=6 count=738381
i=1 j=0 nextVariable=6 count=738382
i=1 j=0 nextVariable=6 count=738383
i=1 j=0 nextVariable=6 count=738384
i=1 j=0 nextVariable=6 count=738385
i=1 j=0 nextVariable=6 count=738386
i=1 j=0 nextVariable=6 count=738387
i=1 j=0 nextVariable=6 count=738388
i=1 j=0 nextVariable=6 count=738389
i=1 j=0 nextVariable=6 count=738390

I have also tried with

i=2 j=1 nextVariable=9 count=201758
i=2 j=1 nextVariable=9 count=201759
i=2 j=0 nextVariable=5 count=201760
i=2 j=1 nextVariable=9 count=201761
i=2 j=1 nextVariable=9 count=201762
i=2 j=1 nextVariable=9 count=201763
i=2 j=1 nextVariable=9 count=201764
i=2 j=0 nextVariable=5 count=201765
i=2 j=1 nextVariable=9 count=201766
i=2 j=1 nextVariable=9 count=201767
i=2 j=1 nextVariable=9 count=201768
i=2 j=1 nextVariable=9 count=201769
i=2 j=0 nextVariable=5 count=201770

I had similar problems with java.util.Random. Is my computer the problem?

5 months ago
In a previous project I have in a class

HibernatePersistence is flagged as deprecated but it worked.  In a new project i could not import org.hibernate.ejb.HibernatePersistence. I read that it is better to use HibernatePersistenceProvider but now I cannot import org.hibernate.jpa.HibernatePersistenceProvider. I have spend hours to find what dependency I should use in Mave without any results.
6 months ago
In the same application breakpoints work in classes, but break points in a controller don't work. Similar we applications in other work spaces work fine with the same tomcat.
Thank you for your help. I tried to use your ideas, but it still doesn't work (well I am just learning).
This is what I did

I also tried to inject BankService in JpaRepository1 but it didn't work.
6 months ago
In a class I have

When running I get  bankRepository null.
I have

6 months ago
All classes must be set in the configuration.

I was missing: "configuration.addAnnotatedClass(Transaction.class);".
I am following a tutorial of Hibernate with Spring. I am trying to add a User object to the database. I am getting the following error: "org.hibernate.AnnotationException: Unknown mappedBy in:, referenced property unknown:
These are my classes

This is pom.xml
Thank you
STS cannot find the annotation @CrossOrigin in a Maven application; I have tried a few dependencies in the pom but to no avail. Now I am trying with code

but it still doesn't work.
Lately I added

But STS cannot find CorsRegistry.

Replace with
8 months ago

I am getting servletContext.addListener not defined in STS. In my pom I have
8 months ago