Skip to content
Advertisement

Tag: random

java- how to generate a 6 digit random hexadecimal value

I have a scenario in a Android app, where a random hexadecimal value has to be generated with 6 digits. (The range of values can be hexadecimal or integer values). What is the most efficient way to do this? Do I have to generate a random decimal number, and then convert it to hexadecimal? Or can a value be directly

Generating a random double in an exclusive range

I’m trying to generate a random floating point number between but not including it’s lower and upper bounds (lower, upper). I’ve seen a lot of questions about generating a number from, and including it’s lower bound up to, but not including it’s upper bound [lower, upper), but that’s not what I’m after. I’ve come up with two “solutions” to the

How can I shuffle the letters of a word?

What is the easiest way to shuffle the letters of a word which is in an array? I have some words in an array and I choose randomly a word but I also want to shuffle the letters of it. I am not supposed to use that List thing. I’ve come up with something like this but with this code

Pick a random value from an enum?

If I have an enum like this: What is the best way to pick one randomly? It doesn’t need to be production quality bulletproof, but a fairly even distribution would be nice. I could do something like this But is there a better way? I feel like this is something that’s been solved before. Answer The only thing I would

How to generate a random alpha-numeric string

I’ve been looking for a simple Java algorithm to generate a pseudo-random alpha-numeric string. In my situation it would be used as a unique session/key identifier that would “likely” be unique over 500K+ generation (my needs don’t really require anything much more sophisticated). Ideally, I would be able to specify a length depending on my uniqueness needs. For example, a

Advertisement