[android-developers] Re: Random() gives same result
I now tryed that and it gave me a java.lang.illegalArgumentException
when it tryes to add cards[0][0]
something more to the code?
On 23 mar, 16:12, Kristopher Micinski <krismicin...@gmail.com> wrote:
> if(i>0){
> t = r.nextInt(i);
> }
>
> should be
>
> if(i>=0){
> t = r.nextInt(i);
> }
>
>
>
> On Fri, Mar 23, 2012 at 11:08 AM, Kristoffer <kris.isak.v...@gmail.com> wrote:
> > Even if this is not Android at least iam using it in a android
> > application ;)
>
> > It seems that you know what you are talking about, do you have the
> > time to point me in the right direction here,
> > is it possible to solve in the way my code works?
>
> > On 23 mar, 15:51, Mark Murphy <mmur...@commonsware.com> wrote:
> >> This has nothing to do with Android. You are not requesting a random
> >> number when i==0.
>
> >> On Fri, Mar 23, 2012 at 10:48 AM, Kristoffer <kris.isak.v...@gmail.com> wrote:
> >> > Hello.
>
> >> > Iam having a problem with the Random()
>
> >> > everything gets random except for cards[0][0] that always ends up with
> >> > = 5
>
> >> > here is the code that i use, anyone have a solution?
> >> > in the code ROW_COUNT = 3 and COL_COUNT = 4
>
> >> > private void loadCards(){
> >> > try{
> >> > int size = ROW_COUNT*COL_COUNT;
>
> >> > ArrayList<Integer> list = new ArrayList<Integer>();
>
> >> > for(int i=0;i<size;i++){
> >> > list.add(new Integer(i));
> >> > }
>
> >> > Random r = new Random();
>
> >> > for(int i=size-1;i>=0;i--){
> >> > int t=0;
>
> >> > if(i>0){
> >> > t = r.nextInt(i);
> >> > }
>
> >> > t=list.remove(t).intValue();
> >> > cards[i%COL_COUNT][i/COL_COUNT]=t%(size/2);
> >> > }
> >> > }
> >> > catch (Exception e) {
> >> > Log.e("loadCards()", e+"");
> >> > }
>
> >> > }
>
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups "Android Developers" group.
> >> > To post to this group, send email to android-developers@googlegroups.com
> >> > To unsubscribe from this group, send email to
> >> > android-developers+unsubscribe@googlegroups.com
> >> > For more options, visit this group at
> >> >http://groups.google.com/group/android-developers?hl=en
>
> >> --
> >> Mark Murphy (a Commons Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> >> _Android Programming Tutorials_ Version 4.1 Available!
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscribe@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home