Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

enum random()

Featured Replies

The issue is that the tabs don't actually switch randomly. Code is compatible but not functioning right.

private static int rngTab = random(0, 125);  
	private enum Tabs {
		ATTACK(0, Tab.ATTACK);
		private int chance;
		private Tab tab;

		public int getChance() {
			return chance;
		}

		public Tab getTab() {
			return tab;
		}

		private static Set<Tabs> tab_set = Collections.unmodifiableSet(EnumSet.allOf(Tabs.class));

		public static Optional<Tabs> forTabs(int rng) {
			return tab_set.stream().filter(Objects::nonNull).filter(tabs -> tabs.getChance() == rng).findAny();
		}

		public static void randomTabs(Script script, int chance) {
			if (rngTab == forTabs(chance).get().getChance()) {
				script.getTabs().open(forTabs(chance).get().getTab());
			}
		}

		private Tabs(int chance, Tab tab) {
			this.chance = chance;
			this.tab = tab;
		}
	}
if (getState() == BotState.FISHING) {
			Tabs.randomTabs(this, 0);
			return;
		}
  • Author
getTabs().open(Tab.values()[random(0, Tab.values().length-1)]);

^ opens a random tab

 

 

omg I had a similar thought like this, embarrassing -.-"

 

Thanks though <3

  • Author

So much overkill in your code x)

I know it's overkill, but little better than using switch.

 

The issue is that the tabs don't actually switch randomly. Code is compatible but not functioning right.

private static int rngTab = random(0, 125);  
	private enum Tabs {
		ATTACK(0, Tab.ATTACK);
		private int chance;
		private Tab tab;

		public int getChance() {
			return chance;
		}

		public Tab getTab() {
			return tab;
		}

		private static Set<Tabs> tab_set = Collections.unmodifiableSet(EnumSet.allOf(Tabs.class));

		public static Optional<Tabs> forTabs(int rng) {
			return tab_set.stream().filter(Objects::nonNull).filter(tabs -> tabs.getChance() == rng).findAny();
		}

		public static void randomTabs(Script script, int chance) {
			if (rngTab == forTabs(chance).get().getChance()) {
				script.getTabs().open(forTabs(chance).get().getTab());
			}
		}

		private Tabs(int chance, Tab tab) {
			this.chance = chance;
			this.tab = tab;
		}
	}
if (getState() == BotState.FISHING) {
			Tabs.randomTabs(this, 0);
			return;
		}

 

 

I know it's overkill, but little better than using switch.

 

Here is something a tad bit more clean and re-usable/generic :)

import java.util.Random;

public class EnumUtil {
    
    public static <T extends Enum<?>> T getRandomEnumValue(Class<T> clazz, Random random) {
        int constants = clazz.getEnumConstants().length;
        if(constants == 0) {
            throw new IllegalArgumentException("Enum class has no constants");
        }
        return clazz.getEnumConstants()[random.nextInt(constants)];
    }

    public static void main(String[] args) {
        Random  random = new Random();
        Tab tab = EnumUtil.getRandomEnumValue(Tab.class, random);
    }
    
}

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.