Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] Skiping numbers with random

Author
Message
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 14th Nov 2022 16:14
So I am a little comfused on how to skip numbers after the last number in random.

I need a random pick from 1 to 11 as there my sprites, and sometimes I will add random(1,3) or random(5.8). But sometimes I need to skip to the end from the last number in my random. So is there a way to skip over numbers with random?

Unless there is another way other then random.

I fell well stupid at this point but as I read the function is limited.

The author of this post has marked a post as an answer.

Go to answer

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Nov 2022 18:11
What do you mean by skip to the end? Random is.... random. It's only purpose is to generate a randomized number. Can you further explain what you're trying to do?
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 14th Nov 2022 18:48
well I have 11 numbers, 1 to 11

I want only numbers 1,2,3,4 to be random but then I need numbers 5,6,7,8,9, to be skiped so numbers 10,11 to be also added.

So i need random to pick from 1 to 4, but also the last two numbers.

Sprites 10 and 11 are bombs and can be on every level, but not all the sprites can be on every level.
JosephB
18
Years of Service
User Offline
Joined: 12th Sep 2006
Location:
Posted: 14th Nov 2022 18:58
Maybe setup an array with the numbers [1, 2, 3, 4, 10, 11] then choose a random number based on the array index 0 to 5.
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 14th Nov 2022 19:02
Quote: "setup an array with the numbers [1, 2, 3, 4, 10, 11]"


Well I am still learning about the new array system and will try this, it makes me fell well, stupid.
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 14th Nov 2022 19:21
I tried this but still am not to sure what it is doing, but I am working on this.

myrandom as integer [ 5 ] = [ 1,3, 5, 7,9,11 ]
MyTyp=random(1,myrandom.length-1)
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 14th Nov 2022 19:55 Edited at: 14th Nov 2022 19:59
This post has been marked by the post author as the answer.
myrandom as integer [6] = [ 1, 3, 5, 7, 9, 11 ] <------------ SHOULD BE 6 NOT 5
MyTyp=myrandom[random(0,myrandom.length)]

1. arrays start from 0. So in the case above you will have element 0, 1, 2, 3, 4, 5 (myrandom.length will return 5)
2. random(0,myrandom.length) will generate a random number between (and including) 0 and 5
3. myrandom[random(0,myrandom.length)] will give you the value from a random element number from your array
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 14th Nov 2022 20:16 Edited at: 14th Nov 2022 20:17
Thank you now i understand ..
Prime
2
Years of Service
User Offline
Joined: 15th Jun 2022
Location:
Posted: 16th Nov 2022 21:25
Quote: "myrandom as integer [6] = [ 1, 3, 5, 7, 9, 11 ] <------------ SHOULD BE 6 NOT 5
MyTyp=myrandom[random(0,myrandom.length)]"


no no @blink0k

myrandom as integer[6] // this is an array with seven integers

myrandom as integer[5] // this is an array with six integers

myrandom as integer[5] = [ 1, 3, 5, 7, 9, 11 ] // this is correct

MyTyp = myrandom[random(0, myrandom.length)] // this selects a random element from indexes 0 to 6 inclusive




PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 16th Nov 2022 21:35
@blinkok
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 16th Nov 2022 22:50
My Bad. Thanks for the correction

Login to post a reply

Server time is: 2024-11-21 12:46:38
Your offset time is: 2024-11-21 12:46:38