0

In an assignment I am completing you have to generate a unique short code for every instance of an object created. As well as an internal ID which I used UUID for. The short code has to be only letters in the format abc-abc-abc. I tried to use the reverse regular expression to generate codes that match a particular pattern but for whatever reason Eclipse does not recognize it, there is no import option.

As a side note each object also has to have a date attached to it. The scenario is a virtual journaling app. So essentially each log would have a date attached for when it was posted. But every time I rerun the program the date updates. I have tried saving the date into a variable with no luck can someone please explain how to accomplish these 2 things. Thanks!

  • 2
    Can you show the code that you tried? And give an example of the unique codes that you are looking for. – Jhanzaib Humayun May 18 '22 at 12:54
  • Could you edit and show what you've tried. Check out [how to ask](https://stackoverflow.com/help/how-to-ask) and [tour](https://stackoverflow.com/tour). – inspectorconfusion May 18 '22 at 12:55
  • After all abc-abc-abc is a 9 digits number in base 26. Thus generate a long value in between 1 and 26^9 and convert it to the appropriate string by successive divisions by 26. – Jean-Baptiste Yunès May 18 '22 at 12:57
  • For random values that you want to be reproductible use a random generator with a given seed. `Random r = new Random(666);` for example. – Jean-Baptiste Yunès May 18 '22 at 12:59
  • You only need to call `char randChar = (char)(rand.nextInt(26) + 'a')` n (9 in your case) times – g00se May 18 '22 at 13:05

0 Answers0