Android Question random number except of one number...

ilan

Expert
Licensed User
Longtime User
can i get a random number except of a specific number?

like dim rnd1 as int = rnd(1,10) but nr 2 & 5 not allowed..

is that possible?
 

Troberg

Well-Known Member
Licensed User
Longtime User
I can do a:

Dim MyArray(10) as MyObject

This tells everyone who is going to use it (which can be future me...) that I'm supposed to put MyObjects in it.

Compare that to:

Dim MyList as List

What am I supposed to put in that one?

Sure, I could (and usually do) do a:

Dim MyList as List ' of MyObject

However, I don't like comments to actually carry a near-syntactical meaning, and the compiler won't tell me I messed up when I try to stuff SomeOtherObject into the list.

I don't argue that lists and maps are useless, quite the contrary, I use them much more than arrays, but that still doesn't mean that arrays are useless.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I can do a:

Dim MyArray(10) as MyObject

This tells everyone who is going to use it (which can be future me...) that I'm supposed to put MyObjects in it.

Compare that to:

Dim MyList as List

What am I supposed to put in that one?

Sure, I could (and usually do) do a:

Dim MyList as List ' of MyObject

However, I don't like comments to actually carry a near-syntactical meaning, and the compiler won't tell me I messed up when I try to stuff SomeOtherObject into the list.

I don't argue that lists and maps are useless, quite the contrary, I use them much more than arrays, but that still doesn't mean that arrays are useless.

This is the only "strong point" of the arrays but used in B4X, because, as I wrote, with VB.Net: "Dim MyList As List Of", you would not have this "problem".

There are not compelling reasons to use arrays yet.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
Don't get me wrong, I'm using maps and lists aswell but it all depends on what you're doing.

for math based lookups/updates I prefer regular arrays as it makes more sense to me to do it like that.

we have the methods available so we have the choice what to choose :)
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
@ilan now we know what your hoping to achieve can I suggest an alternative option?
At the start of your game create a list, array or map (I don't want to enter into that discussion :p) which contains all your random numbers. The list can be easily created just by selecting a random number and add it to the end of the list so long as the previous last number is not the same.

Now your game shouldn't flicker at all, you already have the order in which to load each level just by incrementing through the list as needed. You then have two options. Once you get the the end of the list it could be a level up type of thing and a new list created or you could just continue by going back to the start of the list and continuing. I'm sure that if the list was long enough then nobody would be able to tell.
 
Upvote 0
Top