Advertise here

Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Random No not genrated...

jitendrajitendra Posts: 59New Users @
I want to get the random images from array. images get randomly but some same repetitive images get

i tried this one
for (m = 0; m <=29; m++)
rnd = arc4random_uniform(arr.count-m)+m;

NSString *imageName=[FrontsCards objectAtIndex:rnd];

fullImageName=[NSString stringWithFormat:@"%@",imageName];

int padding=0;

CGRect imageViewFrame=CGRectMake(scrollView.frame.size.width*m+padding, scrollView.frame.origin.y, scrollView.frame.size.width-2*padding, scrollView.frame.size.height);

ImgView=[[UIImageView alloc]initWithFrame:imageViewFrame];

[ImgView setImage:[UIImage imageNamed:fullImageName]];

[scrollView addSubview:ImgView];

[ImgView setAccessibilityIdentifier:[arr objectAtIndex:rnd]];

// Tap Gesture //

UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapImgView:)];
doubleTap.numberOfTapsRequired = 2;
doubleTap.delegate = self;

[self.ImgView addGestureRecognizer:doubleTap];

[self.ImgView setImage:[UIImage imageNamed:fullImageName]];

NSLog(@"full image name %@",fullImageName);

NSLog(@"Image Name = %@", fullImageName);

[self.ImgView setTag:rnd];


NSString *imageName1=[FrontsCards objectAtIndex:rnd];

[tweentyarray addObject:imageName1];


CGSize scrollViewSize=CGSizeMake(scrollView.frame.size.width*30, scrollView.frame.size.height);

[scrollView setContentSize:scrollViewSize];
[self.view addSubview:scrollView];


help me out this thanks in advance.



  • Duncan CDuncan C Posts: 9,112Tutorial Authors, Registered Users @ @ @ @ @ @ @
    random does not mean random, non-repeating.

    If you want random non-repeating, then make a mutable copy of your array. Each time you fetch a random object from the mutable array, remove it from the array. Then when the array is empty, re-fill it with the contents of the original array.
    Duncan C

    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
Sign In or Register to comment.